复制代码 代码如下: <BR>function Button4_onclick(obj) { <BR>obj.focus(); <BR>var rng=document.selection.createRange(); <BR>rng.setEndPoint("StartToStart",obj.createTextRange()); <BR>var eng=document.selection.createRange(); <BR>eng.setEndPoint("EndToEnd",obj.createTextRange()); <BR>var kone = document.getElementByIdx("Text1"); <BR>kone.value=rng.text + "插入字符" + eng.text; <BR>} <BR> value="button" onclick="return Button4_onclick(Text1)" /> 复制代码 代码如下: Inherits="SJLERP.WebForm1" %> <BR>function setCaret(textObj) { <BR>if (textObj.createTextRange) { <BR>textObj.caretPos = document.selection.createRange().duplicate(); <BR>} <BR>} <BR>function insertAtCaret(textObj, textFeildValue) { <BR>if (document.all) { <BR>if (textObj.createTextRange && textObj.caretPos) { <BR>var caretPos = textObj.caretPos; <BR>caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? textFeildValue + ' ' : textFeildValue; <BR>} else { <BR>textObj.value = textFeildValue; <BR>} <BR>} else { <BR>if (textObj.setSelectionRange) { <BR>var rangeStart = textObj.selectionStart; <BR>var rangeEnd = textObj.selectionEnd; <BR>var tempStr1 = textObj.value.substring(0, rangeStart); <BR>var tempStr2 = textObj.value.substring(rangeEnd); <BR>textObj.value = tempStr1 + textFeildValue + tempStr2; <BR>} else { <BR>alert("This version of Mozilla based browser does not support setSelectionRange"); <BR>} <BR>} <BR>} <BR> onselect="setCaret(this);" onclick="setCaret(this);" onkeyup="setCaret(this);" >例子例子例 Forget Never 子例子例子 asp.net onclick="insertAtCaret(this.form.tarea,this.form.textfield.value);"/>