Range:collapsed 属性

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.

Range.collapsed 只读属性返回一个表示 Range 的开始和结束节点是否重合的布尔标志。如果 Range 的开始和结束节点在 DOM 中是同一个位置,则该属性返回 true;反之返回 false

折叠后的 Range 是空的(不含任何内容),并指向 DOM 树中的单个位置点。若要折叠一个范围,请参考 Range.collapse() 方法。

一个布尔值。

示例

js
let range = document.createRange();

range.setStart(startNode, startOffset);
range.setEnd(endNode, endOffset);
isCollapsed = range.collapsed;

规范

Specification
DOM
# ref-for-dom-range-collapsed①

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
collapsed

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

参见