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 March 2017.
语法
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 |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
containsNode | ||||||||||||
partialContainment parameter is optional |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- See implementation notes.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
参考
Selection
, Selection 接口规范。