--- title: Selection.collapse() slug: Web/API/Selection/collapse tags: - API - HTML Editing - Method - Selection translation_of: Web/API/Selection/collapse ---
Selection.collapse()
方法可以收起当前选区到一个点。文档不会发生改变。如果选区的内容是可编辑的并且焦点落在上面,则光标会在该处闪烁。
sel.collapse(parentNode, offset);
parentNode
offset
{{optional_inline}}/* 将光标收起到文档body的开头 */ var body = document.getElementsByTagName("body")[0]; window.getSelection().collapse(body,0);
规范 | 状态 | 备注 |
---|---|---|
{{SpecName('Selection API', '#widl-Selection-collapse-void-Node-node-unsigned-long-offset', 'Selection.collapse()')}} | {{Spec2('Selection API')}} | |
{{SpecName('HTML Editing', '#dom-selection-collapse', 'Selection.collapse()')}} | {{Spec2('HTML Editing')}} | Initial definition |