點選標籤,將標籤內容插入到textarea文件中。
阿新 • • 發佈:2019-02-07
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(); }}
myField.value = beforeValue + myValue + afterValue;
myField.selectionStart = startPos + myValue.length; myField.selectionEnd =