下面是程式碼: 複製程式碼 程式碼如下: ----- -------------------------------------------------- ------------------------- JS在文字網域滑鼠指定位置插入文字-柯樂義 <BR>function insertAtCursor(myField, myValue) {<BR>//IE support<BR>if (document.selection) {<BR>myField.focus() ;<BR>sel = document.selection.createRange();<BR>sel.text = myValue;<BR>sel.select();<BR>}<BR>//MOZILLA/NETSCAPE support <BR>}<BR>//MOZILLA/NETSCAPE support <BR>elseif (myField.selectionStart || myField.selectionStart == '0') {<BR>var startPos = myField.selectionStart;<BR>var endPos = myField.selectionEnd;<BR>// save scrollTop befley <BR>var restoreTop = myField.scrollTop;<BR>myField.value = myField.value.substring(0, startPos) myValue myField.value.substring(endPos, myField.value.length); 0) {<BR>myField.scrollTop = restoreTop;<BR>}<BR>myField.focus();<BR>myField.selectionStart = startPos myValue.length;<BR>myField.selectionStart = startPos myValue.length;<BR>myField.selection = startPos myValue.length;<BR>myField.m. 🎜>} else {<BR>myField.value = myValue;<BR>myField.focus();<BR>}<BR><body} <BR> 柯樂義Javascript 在textarea遊標處插入文字