Skip to content

Latest commit

 

History

History
13 lines (11 loc) · 301 Bytes

选择元素的文本内容.md

File metadata and controls

13 lines (11 loc) · 301 Bytes

选择元素的文本内容

以下方法选择 ele 元素的文本内容:

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