javascript 用鼠标 选择 文字 然后替换 很酷的
<script type="text/javascript">
function changes(obj){
var TextIn=document.getElementById("textin");
if(TextIn.createTextRange){
//ie兼容
TextIn.focus();
document.selection.createRange().duplicate().text=obj;
}else{
//firefox兼容
var iStart = TextIn.selectionStart;
var iEnd = TextIn.selectionEnd;
TextIn.value=TextIn.value.substring(0,iStart)+obj+TextIn.value.substring(iEnd,TextIn.value.length);
endRange=iStart+obj.length;
TextIn.setSelectionRange(endRange,endRange);
}
}
</script>
<textarea cols="40" id="textin">选中这里的文字,然后点change试试看。</textarea><input type="button" onclick="changes('文字被替换了!')" value="change" />