如何选中textarea中指定文字
选中 textarea中指定文字
<textarea cols="40" rows="10" id="target">
<div>php
<div>qqq</div>
</textarea>
怎么让
<div>php</div>
是选中状态
注:textarea 中可以看到 div标记
[解决办法]
<script>function foo(){ var textbox= document.getElementById('target'); selectText(textbox,0,14);}function selectText(textbox,startIndex,stopIndex){ if(textbox.setSelectionRange){ textbox.setSelectionRange(startIndex,stopIndex); }else if(textbox.createTextRange){ var range=textbox.createTextRange(); range.collapse(true); range.moveStart('character',startIndex); range.moveEnd('character',stopIndex-startIndex); range.select(); } textbox.focus();}</script><textarea cols="40" rows="10" id="target"><div>php</div><div>qqq</div></textarea><input type="button" onclick="foo()" value="Click">