您正在阅读此内容的英文版本,因为该语系尚未翻译。 帮助我们翻译此文章吧!
Range.collapse()
方法向边界点折叠该 Range
。
折叠后的 Range
为空,不包含任何内容。
要确定 Range
是否已折叠,使用Range.collapsed
属性。
语法
range.collapse(toStart);
参数
- toStart 可选
- 一个布尔值:
true
折叠到Range
的 start 节点,false
折叠到 end 节点。如果省略,则默认为 false.
例子
var range = document.createRange(); referenceNode = document.getElementsByTagName("div").item(0); range.selectNode(referenceNode); range.collapse(true);
规范
Specification | Status | Comment |
---|---|---|
DOM Range.collapse() |
Living Standard | The parameter is now optional and default to false . |
Document Object Model (DOM) Level 2 Traversal and Range Specification Range.collapse() |
Obsolete | Initial specification. |
浏览器兼容性
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
collapse | Chrome Full support Yes | Edge Full support 12 | Firefox Full support 4 | IE Full support 9 | Opera Full support 9 | Safari Full support Yes | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android ? |
toStart parameter optional | Chrome Full support Yes | Edge ? | Firefox Full support 25 | IE
No support
No
| Opera Full support 15 | Safari Full support Yes | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support 25 | Opera Android Full support 14 | Safari iOS Full support Yes | Samsung Internet Android ? |
Legend
- Full support
- Full support
- No support
- No support
- Compatibility unknown
- Compatibility unknown
- Experimental. Expect behavior to change in the future.
- Experimental. Expect behavior to change in the future.
- See implementation notes.
- See implementation notes.