We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

这篇翻译不完整。请帮忙从英语翻译这篇文章

Range.collapse() 方法向边界点折叠该 Range

折叠后的 Range 为空,不包含节点内容。specifying a single-point in a DOM tree. 要确定 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.

浏览器兼容性

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) (Yes) 1.0 (1.7 or earlier) 9.0 9.0 (Yes)
Parameter optional (Yes) ? 25 (25) 未实现[1] 15.0 (Yes)
Feature Android Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) 1.0 (1.0) 9.0 9.0 (Yes)
Parameter optional (Yes) ? 25 (25) 未实现[1] 15.0 (Yes)

[1] Optional but defaults to true.

See also

文档标签和贡献者

此页面的贡献者: enem
最后编辑者: enem,