暂且定这页面叫edit.html :
- HTML code
<div id="txtEdit"> <div id="show"></div> <div id="editMenu"> <input name="pic" type="button" id="pic" class="btn" value="图片" onclick="danji(this);" /> <input name="video" type="button" id="video" class="btn" value="视频" onclick="danji(this);" /> <input name="link" type="button" id="link" class="btn" value="链接" onclick="danji(this);"/> <input name="bold" type="button" id="bold" class="btn" value="B" onclick="danji(this);"/> <input name="fontB_S" type="button" id="fontB_S" class="btn" value="A" onclick="danji(this);"/> <input name="italic" type="button" id="italic" class="btn" value="I" onclick="danji(this);"/> <input name="underLine" type="button" id="underLine" class="btn" value="U" onclick="danji(this);"/> <input name="chooseColor" type="button" id="chooseColor" class="btn" value="颜色" onclick="chooseColor();" /> <input name="setLeft" type="button" id="setLeft" class="btn" value="居左" onclick="danji(this);" /> <input name="setCenter" type="button" id="setCenter" class="btn" value="居中" onclick="danji(this);"/> <input name="setRight" type="button" id="setRight" class="btn" value="居右" onclick="danji(this);"/> <input name="showface" type="button" id="showface" class="btn" value="表情" onclick="chooseFace();" /> </div> <div id="txtField"> <form id="form1" name="form1" method="post" action="textChange.html" onsubmit="f();"> <textarea name="txt" id="txt" class="txtEdit" ></textarea> <br /> <input name="btnSubmit" type="image" value="提交" src="image/btnSubmit.gif" onclick="this.form.submit();" /> <input name="btnReset" type="image" value="重写" src="image/btnReset.gif" onclick="this.form.reset(); return false;" /> </form> </div> </div>
这是我在edit.html里面写的一段算简单的文本编辑器吧,当然其中引入了js文件和css文件,功能都是可以的。
我想问下,能不能在另一个静态页面(比如1.html)中,用JavaScript引用这个页面来替换1.html页面中的文本域textarea?
还是我需要把这个edit.html改成js文件,再在1.html中调用
------解决方案--------------------
方法一
1.将edit.html里面用的js和css文件在1.html中引入
2.通过Ajax获取edit.html的内容,然后赋予1.html中的某个DOM的innerHTML
3.注意id之类的不要冲突
方法二
将edit.html页面的里的html内容通过js动态生成,并提供接口,这样1.html只要引入js文件和css文件并调用那个接口在指定位置生成简单的文本编辑器就好了
------解决方案--------------------
1.html页面中包含
<a href="edit.html" id="box">
</a>
$('#box').click(function(){
$.post('edit.html',function(){
$('#box').html(data);
}
)
})
------解决方案--------------------