此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

Selection.selectAllChildren()

基线 广泛可用

自 2015年7月 起,此特性已在主流浏览器中得到支持,可在大多数设备和浏览器版本中正常使用。

实验性: 这是一项实验性技术
在将其用于生产之前,请仔细检查浏览器兼容性表格

Selection.selectAllChildren() 把指定元素的所有子元素设为选中区域,并取消之前的选中区域。

语法

js
selectAllChildren(parentNode)

参数

parentNode

所有 parentNode 元素的子元素会被设为选中区域,parentNode 本身除外。

示例

js
footer = document.getElementById("footer");
window.getSelection().selectAllChildren(footer);
/* Everything inside the footer is now selected */

规范

规范
Selection API
# dom-selection-selectallchildren

浏览器兼容性

参见