1. 程式人生 > >點選標籤,將標籤內容插入到textarea文件中。

點選標籤,將標籤內容插入到textarea文件中。

function insertAtCursor(myField, myValue) { if (document.selection) { myField.focus(); sel = document.selection.createRange(); sel.text = myValue; sel.select(); } else if (myField.selectionStart || myField.selectionStart == '0') { var startPos = myField.selectionStart; var
endPos = myField.selectionEnd; var beforeValue = myField.value.substring(0, startPos); var afterValue = myField.value.substring(endPos, myField.value.length);
myField.value = beforeValue + myValue + afterValue;
myField.selectionStart = startPos + myValue.length; myField.selectionEnd =
startPos + myValue.length; myField.focus(); } else { myField.value += myValue; myField.focus(); }}