如果不是ABC呢。如果要改成CAB呢这种需求太那个了把~~~~选中文字出现编辑框倒是可以

解决方案 »

  1.   

    我那是打个比方...当然不会肯定是ABC...我的意思是任意文字都这样...
      

  2.   


    <html>
      <head>
        <meta http-equiv="Content-Type" content="text/html;charset=gb2312" />
        <title>Editor</title>
      </head>
      <body>
        <table width="700px" border="0" cellpadding="0" cellspacing="1" align="center">
         <tr><td><a href="#" onclick="InsertLine()">插入删除线</a></td></tr>
         <tr><td>
           <iframe id="Editor" width="100%" height="300px" marginheight="0" marginwidth="0" frameborder="1"></iframe>
         </td></tr>
        </table>
    <script>
    var ns=navigator.appName=="Netscape";
    var Editor,EditorDoc;
    window.onload=function(){
     Editor=document.getElementById("Editor").contentWindow;
     InitIframe("gb2312");
     EditorDoc=Editor.document;
    }
    function InitIframe(charset){   
     Editor.document.open(); 
     Editor.document.write("<html>");
     Editor.document.write("<head>");
     Editor.document.write("<style type='text/css'>body{font-size:12pt;}</style>");
     Editor.document.write("</head>");
     Editor.document.write("<body></body>");
     Editor.document.write("</html>");
     Editor.document.close(); 
     Editor.document.body.contentEditable="true";
     Editor.document.designMode="On";
     Editor.document.charset=charset;
     Editor.focus();
    }
    function InsertLine(){
     var r=ns?EditorDoc.createRange():EditorDoc.selection.createRange();
     var txt=ns?EditorDoc.getSelection():r.text;
     if(txt==""){alert('请先选择删除的文字!');return;}
     var v=prompt("输入替换的值","");
     while(v=="")v=prompt("输入替换的值","");
     if(ns){//ff需要2步完成
      var s=document.createElement("strike");s.innerHTML=v;
      Editor.window.getSelection().getRangeAt(0).surroundContents(s);  
      Editor.focus();
      var sp=document.createElement("span");sp.style.color='red';sp.innerHTML=v;
      EditorDoc.body.insertBefore(sp,s.nextSibling);
     }
    //ie使用pasteHTML就搞定了
     else r.pasteHTML("<strike>"+txt+"</strike><span style='color:red'>"+v+'</font>');
    }
    </script>
      </body>
    </html>