📅  最后修改于: 2022-03-11 15:02:56.407000             🧑  作者: Mango
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