javascript实现 在光标处插入指定内容
作者:
javascript实现 在光标处插入指定内容
<TEXTAREA ROWS="20" COLS="100" id='test'>123456798<B>123</B></TEXTAREA>
<INPUT TYPE="button" value='insert("abc")' OnClick='_insertText("abc")'>
<SCRIPT LANGUAGE="JavaScript">
<!--
var _insertText = function(A){
var B = document.getElementById('test');
B.focus();
var C = document.selection.createRange();
if(C){
if(C.text.length > 0) C.text += A;
else C.text= A;
C.select();
}
}
//-->
</SCRIPT>
<INPUT TYPE="button" value='insert("abc")' OnClick='_insertText("abc")'>
<SCRIPT LANGUAGE="JavaScript">
<!--
var _insertText = function(A){
var B = document.getElementById('test');
B.focus();
var C = document.selection.createRange();
if(C){
if(C.text.length > 0) C.text += A;
else C.text= A;
C.select();
}
}
//-->
</SCRIPT>