Skip to content

contenteditable

设置光标到内容最后

js
function setEndOfContenteditable(elem) {
  let sel = document.getSelection()
  sel.selectAllChildren(elem)
  sel.collapseToEnd()
  return sel
}

获取最后修改位置

js
function getLastEditRange() {
  let sel = document.getSelection()
  return sel.getRangeAt(0)
}