遇到一個功能,要求點擊標題,插入文字到已有的文本中。
主要代碼如下:
var txtArea = $("#textArea")[0]; var content = txtArea.value; var start = txtArea.selectionStart; //初始位置 txtArea.value = content.substring(0, txtArea.selectionStart) + $(this).text() + content.substring(txtArea.selectionEnd, content.length); var position = start + $(this).text().length; $("#textArea").focus(); txtArea.setSelectionRange(position, position);