Selection.containsNode()

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

Selection.containsNode() 判断指定的节点是否包含在 Selection 中 (是否被选中).

语法

sel.containsNode(aNode,aPartlyContained)

参数

aNode

用于判断是否包含在 Selection 中的那个节点

aPartlyContained

当此参数为true 时, 当selection 包含节点 aNode 的一部分或全部时,containsNode() 返回 true. 当此参数为false 时, 只有当 selection 完全包含节点 aNode 时,containsNode() 才返回 true.

例子

 /* 检查 body 中是否有节点被选中 */
 console.log(window.getSelection().containsNode(document.body, true));

规范

Specification
Selection API
# dom-selection-containsnode

浏览器兼容性

BCD tables only load in the browser

参考