代码继续,直接接着上面的代码复制就可用
 <TD class=ico4>&nbsp;</TD>
          <TD style="FONT-SIZE: 12px">&nbsp;</TD>
          <TD style="FONT-SIZE: 12px" width="60"><INPUT language=javascript 
            onmouseover=fSetModeTip(this) onclick=setMode(this.checked) 
            onmouseout=fHideTip() type=checkbox name=switchMode> HTML</TD>
 <TD width="20"><IMG src="htmlEdit.files/editor_s.gif"></TD>
          <TD style="FONT-SIZE: 12px"><IMG onmousedown=fSetBorderMouseDown(this) 
            onmouseover=fSetBorderMouseOver(this) title=增加文本框 onclick=doInsertInputRadio() 
            onmouseout=fSetBorderMouseOut(this) height=20 
            src="htmlEdit.files/editor_radio.gif" width=21></TD>
<TD style="FONT-SIZE: 12px"><IMG onmousedown=fSetBorderMouseDown(this) 
            onmouseover=fSetBorderMouseOver(this) title=增加文本框 onclick=doInsertInputText() 
            onmouseout=fSetBorderMouseOut(this) height=20 
            src="htmlEdit.files/editor_text.gif" width=21></TD>

    </TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<DIV id=dvForeColor 
style="DISPLAY: none; LEFT: -500px; WIDTH: 100px; POSITION: absolute; TOP: -500px; HEIGHT: 100px">
<TABLE style="BORDER-RIGHT: #888888 1px solid; BORDER-TOP: #888888 1px solid; BORDER-LEFT: #888888 1px solid; BORDER-BOTTOM: #888888 1px solid" 
height=25 cellSpacing=0 cellPadding=0 width=218>
  <TBODY>
  <TR>
    <TD id=tdView width=110>&nbsp;</TD>
    <TD id=tdColorCode align=middle bgColor=#ffffff></TD></TR></TBODY></TABLE></DIV>
<DIV id=dvPortrait style="DISPLAY: none; LEFT: -500px; WIDTH: 100px; POSITION: absolute; TOP: -500px; HEIGHT: 100px"></DIV>
<DIV id=fontface style="BORDER-RIGHT: #838383 1px solid; PADDING-RIGHT: 1px; BORDER-TOP: #838383 1px solid; DISPLAY: none; PADDING-LEFT: 1px; Z-INDEX: 99; BACKGROUND: #ffffff; LEFT: 2px; PADDING-BOTTOM: 1px; BORDER-LEFT: #838383 1px solid; WIDTH: 110px; PADDING-TOP: 1px; BORDER-BOTTOM: #838383 1px solid; POSITION: absolute; TOP: 35px; HEIGHT: 270px">
<A class=n style="FONT: 12px '宋体'" 
onclick="format('fontname',this.innerHTML);this.parentNode.style.display='none'" 
href="javascript:void(0)">宋体</A><A class=n style="FONT: 12px '黑体'" 
onclick="format('fontname',this.innerHTML);this.parentNode.style.display='none'" 
href="javascript:void(0)">黑体</A><A class=n style="FONT: 12px '楷体'" 
onclick="format('fontname',this.innerHTML);this.parentNode.style.display='none'" 
href="javascript:void(0)">楷体</A><A class=n style="FONT: 12px '隶书'" 
onclick="format('fontname',this.innerHTML);this.parentNode.style.display='none'" 
href="javascript:void(0)">隶书</A><A class=n style="FONT: 12px '幼圆'" 
onclick="format('fontname',this.innerHTML);this.parentNode.style.display='none'" 
href="http://www.e077.com/html/###">幼圆</A><A class=n style="FONT: 12px Arial" 
onclick="format('fontname',this.innerHTML);this.parentNode.style.display='none'" 
href="http://www.e077.com/html/###">Arial</A><A class=n 
style="FONT: 12px 'Arial Narrow'" 
onclick="format('fontname',this.innerHTML);this.parentNode.style.display='none'" 
href="http://www.e077.com/html/###">Arial Narrow</A><A class=n 
style="FONT: 12px 'Arial Black'" 
onclick="format('fontname',this.innerHTML);this.parentNode.style.display='none'" 
href="http://www.e077.com/html/###">Arial Black</A><A class=n 
style="FONT: 12px 'Comic Sans MS'" 
onclick="format('fontname',this.innerHTML);this.parentNode.style.display='none'" 
href="http://www.e077.com/html/###">Comic Sans MS</A><A class=n 
style="FONT: 12px Courier" 
onclick="format('fontname',this.innerHTML);this.parentNode.style.display='none'" 
href="http://www.e077.com/html/###">Courier</A><A class=n 
style="FONT: 12px System" 
onclick="format('fontname',this.innerHTML);this.parentNode.style.display='none'" 
href="http://www.e077.com/html/###">System</A><A class=n 
style="FONT: 12px 'Times New Roman'" 
onclick="format('fontname',this.innerHTML);this.parentNode.style.display='none'" 
href="javascript:void(0)">Times New Roman</A><A class=n 
style="FONT: 12px Verdana" 
onclick="format('fontname',this.innerHTML);this.parentNode.style.display='none'" 
href="javascript:void(0)">Verdana</A></DIV>
<DIV id=fontsize 
style="BORDER-RIGHT: #838383 1px solid; PADDING-RIGHT: 1px; BORDER-TOP: #838383 1px solid; DISPLAY: none; PADDING-LEFT: 1px; BACKGROUND: #ffffff; LEFT: 26px; PADDING-BOTTOM: 1px; BORDER-LEFT: #838383 1px solid; WIDTH: 115px; PADDING-TOP: 1px; BORDER-BOTTOM: #838383 1px solid; POSITION: absolute; TOP: 35px; HEIGHT: 160px"><A 
class=n style="FONT-SIZE: xx-small; LINE-HEIGHT: 120%" 
onclick="format('fontsize',1);this.parentNode.style.display='none'" 
href="javascript:void(0)">极小</A><A class=n 
style="FONT-SIZE: x-small; LINE-HEIGHT: 120%" 
onclick="format('fontsize',2);this.parentNode.style.display='none'" 
href="javascript:void(0)">特小</A><A class=n 
style="FONT-SIZE: small; LINE-HEIGHT: 120%" 
onclick="format('fontsize',3);this.parentNode.style.display='none'" 
href="javascript:void(0)">小</A><A class=n 
style="FONT-SIZE: medium; LINE-HEIGHT: 120%" 
onclick="format('fontsize',4);this.parentNode.style.display='none'" 
href="http://www.e077.com/html/##">中</A><A class=n 
style="FONT-SIZE: large; LINE-HEIGHT: 120%" 
onclick="format('fontsize',5);this.parentNode.style.display='none'" 
href="javascript:void(0)">大</A><A class=n 
style="FONT-SIZE: x-large; LINE-HEIGHT: 120%" 
onclick="format('fontsize',6);this.parentNode.style.display='none'" 
href="javascript:void(0)">特大</A><A class=n 
style="FONT-SIZE: xx-large; LINE-HEIGHT: 140%" 
onclick="format('fontsize',7);this.parentNode.style.display='none'" 
href="javascript:void(0)">极大</A></DIV>
<DIV id=divEditor>
<table width="100%" height:287px border="0" cellspacing="0" cellpadding="0" >
<tr><td style="border:1px solid #C5C5C5; border-top:0;">
<IFRAME class="HtmlEditor" ID="HtmlEditor" name="HtmlEditor" 
style="height:286px;width:100%" frameBorder="2" marginHeight=0 marginWidth=0></IFRAME></td>
</tr>
</table>
</DIV>
<input type = button value="点我" onclick= test() >
<SCRIPT language=JavaScript>
function test(){
//var node = document.getElementById("HtmlEditor");
//var html = node.innerHTML
}
<!--
if(document.all){
document.write('<textarea ID="sourceEditor" style="height:280px;width:100%;display:none">');
}else{
document.write('<textarea ID="sourceEditor" style="height:282px;width:100%;display:none">');
}
//-->
</SCRIPT>
</BODY></HTML>

解决方案 »

  1.   

    <script>
    function testwts(){
        document.getElementById("aim").value=HtmlEditor.document.body.innerHTML;
        alert(HtmlEditor.document.body.innerHTML);}
    </script>
    <input type = button value="点我" onclick= testwts() >
    <textarea id="aim">
    </textarea>HtmlEditor.document.body.innerHTML这句如果不行就改成document.getElementById("HtmlEditor").document.body.innerHTML;
      

  2.   

    忘记加引号了....
    <input type = button value="点我" onclick="testwts();" > 
      

  3.   

    第一个可以,我爱死你了根据你的代码,我猜想iframe应该也相当于一个doc页面,是这样吧。。
      

  4.   

    太长了!!!大概得看了下需要获取iframe操作iframe可以参考if (eWebEditor1.getHTML()=="") {
    alert("内容不能为空!");
    return false;
    }<textarea name="Content" style="display:none"></textarea>
         <iframe ID="eWebEditor1" src="editor.asp?id=Content&style=news&originalfilename=d_originalfilename&savefilename=d_savefilename&savepathfilename=d_savepathfilename" frameborder="0" scrolling="no" width="100%" HEIGHT="360"></iframe>
      

  5.   

    function getHTML() {
    var html;
    if((sCurrMode=="EDIT")||(sCurrMode=="VIEW")){
    html = eWebEditor.document.body.innerHTML;
    }else{
    html = eWebEditor.document.body.innerText;
    }
    if (sCurrMode!="TEXT"){
    if ((html.toLowerCase()=="<p>&nbsp;</p>")||(html.toLowerCase()=="<p></p>")){
    html = "";
    }
    }
    return html;
    }
      

  6.   

    现成的,看JS文件里的setMode()函数,就是显示HTML源码的那个
      

  7.   

    考虑兼容的话还可以考虑下obj.contentDocument/obj.contentWindow
      

  8.   

    3楼的代码可以得到html编码,我试过了,我想再问大家一个问题,假如我有一个1.html页面,这个页面定义了一个iframe,它的src是上面我写的那个html编辑器页面,当我在1.html点击一个按钮的之后提交请求给一个action,那这个action如何得到html编辑器编辑的代码啊?
      

  9.   

    <form method="post" action="要提交到的页面" onsubmit="CopyData(this);"><!--提交时执行内容复制-->
    <input type="hidden" name="editor"/><!---加个隐藏控件来获取编辑器中的代码,服务器就获取这个控件的值---->
    <iframe src='editor.html' id="Editor"></iframe><!-----假设编辑器为editor.html----->
    </form>
    <script>
    function CopyData(f)
    {
      var ct=document.getElementById("Editor").HtmlEditor.document.body.innerHTML;//获取frame中的编辑器内容
      f.editor.value=ct;
    }
    </script>
      

  10.   

    我也是这样想的,设个隐藏域,把html编辑器编辑的代码做为一个String赋给hidden标签,在到action里面使用request.getParameter("editor"),就能获得吧。
    不过这个hidden能容纳多大的内容啊,html代码好像有点长哦
      

  11.   


    你的form是post时没问题,可以容纳
      

  12.   

    http://www.lokcore.com/avrilxu/article.asp?id=8
    看看这个吧
      

  13.   

    大侠,再帮我个忙,你这个代码是可以再当前的html编辑器获得内容,那假如如果我有个1.html页面,这个页面也定义了一个iframe,
    如同12楼所说的那样form method="post" action="要提交到的页面" onsubmit="CopyData(this);"><!--提交时执行内容复制-->
    <input type="hidden" name="editor"/><!---加个隐藏控件来获取编辑器中的代码,服务器就获取这个控件的值---->
    <iframe src='editor.html' id="Editor"></iframe><!-----假设编辑器为editor.html----->
    </form>
    <script>
    function CopyData(f)
    {
      var ct=document.getElementById("Editor").HtmlEditor.document.body.innerHTML;//获取frame中的编辑器内容
      f.editor.value=ct;
    }
    </script>我试过了它的方法,1.html不能获得editor.html里面的编辑的内容?
    你能给我正确的吗,我看的有点糊涂
      

  14.   

    应该这样说
    如果 你想在调用该在线编辑器的 页面中 改动尽可能少的话就用setInterval
    如果 你只是在少量的页面中使用了该在线编辑器的话在submit事件中添加一下就可以了
      

  15.   

    我试过你的方法了
    var ct=document.getElementById("Editor").HtmlEditor.document.body.innerHTML;
    报错啊,你试了吗?可能还是那里有问题啊。。