<SCRIPT>
function storeCaret(textEl)
{
if(textEl.createTextRange)
textEl.caretPos = document.selection.createRange().duplicate();
}
function insertAtCaret(textEl,text){
if(textEl.createTextRange && textEl.caretPos){
var caretPos = textEl.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == '' ? text + '' : text;
}
else
textEl.value = text;
}
</SCRIPT>
<FORM name=aForm>
<TEXTAREA onkeyup=storeCaret(this); onclick=storeCaret(this); name=aTextArea rows=5 cols=80 onselect=storeCaret(this);>测试测试测试测试测试测试</TEXTAREA>
<INPUT size=80 value=要插入的文字 name=aText>
<INPUT onclick=insertAtCaret(this.form.aTextArea,this.form.aText.value); type=button value=在光标处插入>
</FORM>