本帖最后由 net_lover 于 2012-02-12 11:54:30 编辑

解决方案 »

  1.   

    document.getElementById("<%=ReplyConn.ClientID%>").value=s
    这个我早就用过了,没用。我去试试下面那个看看、
      

  2.   

    还有一个就是<textarea>是编辑器。我要往编辑器里面赋值是不是需要别的方法?
      

  3.   

    您说的没错,我刚新建了一个<textarea>没有加编辑器的那种测试了,是可以传值的。可是我不知道如何将值赋到加了编辑器的<textarea>里面去。
      

  4.   


    你需要调用编辑器提供插入功能,一般的编辑器都有这样方法的,
    如果单纯是textarea,可以这样
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "  http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="  http://www.w3.org/1999/xhtml">
     <head>
      <meta http-equiv="content-type" content="text/html;charset=gb2312" />
     </head>
    <body>
      <br ><iframe style="width:300px;height:200px" id="editor"></iframe>
      <br >内容:<input type="text" id="txt" onmousedown="SaveRange()" /><input type="button" onclick="insert()" onmousedown="SaveRange()"  value="插入输入的字符在HTML编辑器原位置" />
      <script type="text/javascript">
      var isIE=!!document.all,ieRange=false,editor,win,doc,txt;
      window.onload=function(){
        editor=document.getElementById('editor');
        win=editor.contentWindow;
        doc=win.document;
        txt=document.getElementById('txt');    
        doc.designMode='On';//可编辑
        win.focus();
      }
      function SaveRange(){//IE下保存Range对象
        if(isIE&&!ieRange){//是否IE并且判断是否保存过Range对象
          var sel=doc.selection;
            ieRange=sel.createRange();
            if(sel.type!='Control'){//选择的不是对象
              var p=ieRange.parentElement();//判断是否在编辑器内
              if(p.tagName=="INPUT"||p==document.body)ieRange=false;
          }
        }
      }
      function insert(){
        if(txt.value==''){alert('请输入内容!'); txt.focus();return false;}
        if(ieRange){
          ieRange.pasteHTML(txt.value);
          txt.value='';
          ieRange.select();ieRange=false;//清空下range对象
        }
        else{//焦点不在html编辑器内容时
           win.focus();
           if(isIE)doc.body.innerHTML+=txt.value;//IE插入在最后
           else{//Firefox
             var sel=win.getSelection(),rng=sel.getRangeAt(0),frg=rng.createContextualFragment(txt.value);
             rng.insertNode(frg);
           }
        }
      }
      </script> 
    </body>
    </html>
      

  5.   

    win=editor.contentWindow是只能用在<frame>或<iframe>。
    我需要把编辑器放到 这两个标签之一里面去吗?
      

  6.   

    我的编辑器是在一个叫"XHtmlEdit"的文件里面,谁知道这个编辑器提供的数据插入功能吗?