📌  相关文章
📜  选择不输入元素文本 JS - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:56.407000             🧑  作者: Mango

代码示例1
document.querySelector('button').addEventListener('click', function(){
    var range = document.createRange();
    var selection = window.getSelection();
    range.selectNodeContents(document.querySelector('p')); // the element want to select it's content
    
    selection.removeAllRanges();
    selection.addRange(range);
});

// https://developer.mozilla.org/en-US/docs/Web/API/range/selectNodeContents