如何用innerHTML 或者innerText在印象笔记编辑框的光标处插入内容?

12style
  • 38

用下面的JavaScript代码,插入内容后格式都乱了,只能插入编辑框最顶部,如何在印象笔记编辑框的光标处插入内容?

function typeInTextarea(newText, el = document.activeElement) {
  const start = el.selectionStart
  const end = el.selectionEnd
  const text = el.innerText
  const before = text.substring(0, start)
  const after  = text.substring(end, text.length)
  el.innerText = (before + newText + after)
  el.selectionStart = el.selectionEnd = start + newText.length
  el.focus()
}
回复
阅读 539
1 个回答

document.execCommand("insertText", "false", text);

宣传栏