Selection:selectAllChildren() 方法
Selection.selectAllChildren() 方法将指定节点的全部子节点添加到选区。之前的选区将被移除。
语法
js
selectAllChildren(parentNode)
参数
parentNode-
parentNode的所有子节点都将被选中。parentNode本身不包含在选区内。
返回值
无(undefined)。
示例
HTML
html
<main>
<button>Select Footer</button>
<p>Welcome to my website.</p>
<p>I hope you enjoy your visit.</p>
</main>
<footer>
<address>webmaster@example.com</address>
<p>© 2019</p>
</footer>
JavaScript
js
const button = document.querySelector("button");
const footer = document.querySelector("footer");
button.addEventListener("click", (e) => {
window.getSelection().selectAllChildren(footer);
});
结果
规范
| 规范 |
|---|
| Selection API # dom-selection-selectallchildren |
浏览器兼容性
加载中…
另见
Selection,它所属的接口。