Selection:isCollapsed 属性

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.

Selection.isCollapsed 只读属性返回一个布尔值,表示当前是否有任何文本被选中。当选定内容的起点和终点位于内容中的同一位置时,没有选定文本。

请注意,折叠的选择可能仍有一个(在 Gecko 中为多个)Range,因此 Selection.rangeCount 可能不为零。在这种情况下,调用 Selection 对象的 getRangeAt() 方法可能会返回折叠的 Range 对象。

一个布尔值。

规范

Specification
Selection API
# dom-selection-iscollapsed

浏览器兼容性

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
isCollapsed

Legend

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

Full support
Full support

参见