在我用ftb时,很想在客户端用js对ftb的编辑框进行操作,在使用ftb的页面中查看了dom树,发现ftb服务器端控件给客户端发过来的只有三个div,分别对应 :编辑模式,html模式和预览模式(仅限于编辑区)代码如下:
1
<
div
id
="content_designEditorArea"
style
="clear:both;padding-top:1px;"
>
2 < iframe id ="content_designEditor" style ="padding: 0px; width:598px; height: 349px;" src ="about:blank" class ="content_DesignBox" ></ iframe >
3 </ div >
4 < div id ="content_htmlEditorArea" style ="clear:both;display:none;padding-bottom:1px;" >
5 < textarea id ="content" name ="content" disabled ="disabled" style ="padding: 0px; width:600px; height: 350px;" class ="content_HtmlBox" > 3 </ textarea >
6 </ div >
7 < div id ="content_previewPaneArea" style ="clear:both;display:none;padding-bottom:1px;" >
8 < iframe id ="content_previewPane" style ="padding: 0px; width:598px; height: 349px" src ="about:blank" class ="content_DesignBox" ></ iframe >
9 </ div >
看到代码,我很高兴,因为有比较熟悉的id为content的textarea,思路马上清晰了,直接用js往textarea的innerText属性加内容就可以了不是(你真是太有才了)。
2 < iframe id ="content_designEditor" style ="padding: 0px; width:598px; height: 349px;" src ="about:blank" class ="content_DesignBox" ></ iframe >
3 </ div >
4 < div id ="content_htmlEditorArea" style ="clear:both;display:none;padding-bottom:1px;" >
5 < textarea id ="content" name ="content" disabled ="disabled" style ="padding: 0px; width:600px; height: 350px;" class ="content_HtmlBox" > 3 </ textarea >
6 </ div >
7 < div id ="content_previewPaneArea" style ="clear:both;display:none;padding-bottom:1px;" >
8 < iframe id ="content_previewPane" style ="padding: 0px; width:598px; height: 349px" src ="about:blank" class ="content_DesignBox" ></ iframe >
9 </ div >
马上行动,代码如下:
content.innerText = value;
既然问题找到,看来要换换思路了---对普通编辑模式下的id为 content_htmlEditorArea的iframe进行处理了,进行的很顺利,问题解决了,代码如下:
content_designEditor.document.body.innerHTML
=
value;
上面的代码告诉我们一个页面里的iframe,不论它的src有没有值,它都相当与一个新的document。