Selection.containsNode()
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
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> |
浏览器兼容性
Loading…
参考
Selection, Selection 接口规范。