Skip to content

选中元素的文本内容

INFO

鼠标选中文字效果

js
const selectText = function (ele) {
  const range = document.createRange()
  range.selectNodeContents(ele)
  const selection = window.getSelection()
  selection.removeAllRanges()
  selection.addRange(range)
}

如有转载或 CV 的请标注本站原文地址