I am net_lover,If you wanna email to net_lover,you can send a mail to him!
<FORM name="search">
要查找的字符:<INPUT onchange="n = 0;" size=15 name="string" value="net_lover">
替换成:<INPUT name="rpl" value="【孟子E章】">
<INPUT type=button value="查找" onclick="findInPage(string.value,0);">
</FORM>
<SCRIPT language=JavaScript>
 var NS4 = (document.layers);
 var IE4 = (document.all);
 var win = window;
 var n = 0;
 function findInPage(str,bln) {
 var txt, i, found;
 if (str == "")
 return false;
 if (NS4) {
 if (!win.find(str))
 while(win.find(str, false, true))
 n++;
 else
 n++;
 if (n == 0)
 alert("Not found.");
 } if (IE4) {
 txt = win.document.body.createTextRange();
 for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {
 if(bln==0){
 txt.moveStart("character", 1);
  }
 else
 txt.moveStart("character", 0);
 txt.moveEnd("textedit");
 }
 if (found) {
 txt.moveStart("character", -1);
 txt.findText(str);
 txt.scrollIntoView(); 
 txt.select();
 if(confirm("你要替换吗?"))
 txt.text=document.search.rpl.value
 txt.moveEnd("textedit");
 n++;
 }
 else {
 if (n >0) {
 n = 0;
 findInPage(str);
 }
}
}
return false;
}
</SCRIPT>

解决方案 »

  1.   

    http://lucky.myrice.com/javascriptexam/textrange.htm
      

  2.   

    <body bgcolor="#0099FF" text="#FFFFFF">
    <FORM name="search">
    <textarea name="textarea" cols="50" rows="20">这里是测试文字,选net_lover中文字,然后可net_lover以在选中的文字两边加上代码,也可以自己输入要加入的东西。只需要再增加一个输入框即可。</textarea><br>
    要查找的字符:<INPUT onchange="n = 0;" size=15 name="string" value="net_lover">
    替换成:<INPUT name="rpl" value="【孟子E章】">
    <INPUT type=button value="查找" onclick="findInPage(string.value,0);">
    <SCRIPT language=JavaScript>
     var NS4 = (document.layers);
     var IE4 = (document.all);
     var win = window;
     var n = 0;
     function findInPage(str,bln) {
     var txt, i, found;
     if (str == "")
     return false;
     if (NS4) {
     if (!win.find(str))
     while(win.find(str, false, true))
     n++;
     else
     n++;
     if (n == 0)
     alert("Not found.");
     } if (IE4) {
     txt = win.document.search.textarea.createTextRange();
     for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {
     if(bln==0){
     txt.moveStart("character", 1);
      }
     else
     txt.moveStart("character", 0);
     txt.moveEnd("textedit");
     }
     if (found) {
     txt.moveStart("character", -1);
     txt.findText(str);
     txt.scrollIntoView();
     txt.select();
     if(confirm("你要替换吗?"))
     txt.text=document.search.rpl.value
     txt.moveEnd("textedit");
     n++;
     }
     else {
     if (n >0) {
     n = 0;
     findInPage(str);
     }
    }
    }
    return false;
    }
    </SCRIPT>
    </form>