<textarea id=rrr></textarea>
<script>
document.all.rrr.focus();
rng=document.selection.createRange();
rng.text="新的内容"
</script>

解决方案 »

  1.   

    <textarea id=rrr></textarea><br>
    输入要替换的内容<input type=text name=txt><input type=button value="替换" onclick="ReplaceText(document.all.txt.value)"
    <script>
    function ReplaceText(replacestr){
    document.all.rrr.focus();
    rng=document.selection.createRange();
    rng.text=replacestr;
    }
    </script>
      

  2.   

    <textarea id=textarea1>0123</textarea><br>
    输入要查找的内容<input type=text name=input1 value=12><input type=button value="查找" onclick="findText(textarea1,input1)">
    <script>
    function findText(oTextArea,oInput){
    var rng=oTextArea.createTextRange()
    rng.findText(oInput.value)
    rng.select();
    }
    </script>
    findText Method--------------------------------------------------------------------------------Searches for text in the document, and positions the start and end points of the range to encompass the search string. SyntaxbFound = TextRange.findText(sText [, iSearchScope]  [, iFlags])ParameterssText Required. String that specifies the text to find. 
    iSearchScope Optional. Integer that specifies the number of characters to search from the starting point of the range. A positive integer indicates a forward search; a negative integer indicates a backward search.  
    iFlags Optional. Integer that specifies one or more of the following flags to indicate the type of search: 2 Match whole words only. 
    4 Match case. 
     Return ValueBoolean. Returns true if the search text is found, or false otherwise.
      

  3.   


    iFlags没有理解是什么意思
      

  4.   

    <textarea id=textarea1>01233120</textarea><br>
    输入要查找的内容<input type=text name=input1 value=12>
    <p>
    输入要替换的内容<input name=input2 value='As you like'>
    <input type=button value="查找" onclick="findText(textarea1,input1.value)">
    <input type=button value="替换" onclick="replaceText(textarea1,input2.value)">
    <input type=button value="查找替换全部" onclick=reAll()>
    <script>
    function findText(oTextArea,oInput){
    var rng=oTextArea.createTextRange()
    var bFlag=rng.findText(oInput)
    rng.select();
    return bFlag;
    }
    function replaceText(oTextArea,toReplace){
    oTextArea.focus();
    var rng=document.selection.createRange();
    if(rng.text.length<=0)return;
    rng.text=toReplace;
    }
    function reAll(){
    while(findText(textarea1,input1.value)) replaceText(textarea1,input2.value);
    }
    </script>
      

  5.   

    iFlags Optional. Integer that specifies one or more of the following flags to indicate the type of search: 
    2 Match whole words only. 当作词查找
    4 Match case. 大小写匹配