http://www.cnblogs.com/yczsj/archive/2007/05/14/745814.aspx搞掂!

解决方案 »

  1.   

    是的,input是不行的现在我又遇到难题:
    appendChild方法只在最后面添加,我想在光标后面添加,可以做到么?
      

  2.   

    设置textarea的背景图片样式搞掂.
      

  3.   

    不行,插入多个图片又出问题
    我现在考虑在线编辑器:
    <html>
    <head>
        <title>无标题页</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
    </head>
    <body>
    <!--作为编辑区的iframe-->
    <iframe id="x"  style="width:100%;height:296px;" marginWidth='0' marginHeight='0'></iframe>
    <br /><input type="button" onclick="t('UnderLine')" value="下划线" />
    <input type="button" onclick="t('bold')" value="粗体" id="Button1" />
    <input type="button" onclick="t('JustifyLeft')" value="左对齐" />
    <input type="button" onclick="t('JustifyCenter')" value="居中对齐" />
    <input type="button" onclick="t('JustifyRight')" value="右对齐" /><input type="button" onclick="t2()" value="增高" />
    <input type="button" onclick="t3()" value="减少" /><script type="text/javascript" language="javascript">
    editer = document.getElementById('x').contentWindow;
    editer.document.designMode="On";
    editer.document.contentEditable = true;editer.document.open();
    editer.document.writeln('<html><body></body></html>');
    editer.document.close();
    editer.focus();
        
    function t(s)
    {
    editer.focus(); //获取当前iframe的焦点
    //获取文本框中选中区内容
    o = editer.document.selection.createRange();
    //在当前文档、选中区或给定范围上执行命令
    editer.document.execCommand(s);
    }//增高
    function t2(){
      var obj=editer.frameElement;
      
      var height = parseInt(obj.offsetHeight);//获取iframe的高度
      
      if (height+100 >= 100){
    obj.style.height = height+100;
      }
    }
    //减低
    function t3(){
      var obj=editer.frameElement;
      
      var height = parseInt(obj.offsetHeight);
      
      if (height-100 >= 100){
    obj.style.height = height-100;
      }
    }
    </script> </body>
    </html>
    这样就好玩了
    http://www.jw112.com/asp/html/181l1.htm