--- title: Selection.removeAllRanges() slug: Web/API/Selection/removeAllRanges translation_of: Web/API/Selection/removeAllRanges ---
{{ ApiRef("DOM") }}{{SeeCompatTable}}

Selection.removeAllRanges()方法会从当前selection对象中移除所有的range对象,取消所有的选择只 留下{{domxref("Selection.anchorNode", "anchorNode")}} 和{{domxref("Selection.focusNode","focusNode")}}属性并将其设置为null。

语法

sel.removeAllRanges();

参数

无。

规范

 

规范 状态 注释
{{SpecName('HTML Editing', '#dom-selection-removeallranges', 'Selection.removeAllRanges()')}} {{Spec2('HTML Editing')}} Initial definition
{{SpecName('Selection API', '#widl-Selection-removeAllRanges-void', 'Selection.removeAllRanges()')}} {{Spec2('Selection API')}} Current

 

浏览器兼容性

{{Compat("api.Selection.removeAllRanges")}}

相关链接