--- title: Range.deleteContents() slug: Web/API/Range/deleteContents tags: - API - DOM - Method - Range translation_of: Web/API/Range/deleteContents ---

{{ApiRef("DOM")}}

Range.deleteContents() 移除来自 {{ domxref("Document") }}的{{ domxref("Range") }} 内容。

不像{{ domxref("Range.extractContents") }}一样,本方法不会返回一个包含删除内容的文本片段{{domxref("DocumentFragment")}} 。

语法

range.deleteContents()

例子

range = document.createRange();
range.selectNode(document.getElementsByTagName("div").item(0));
range.deleteContents();

规范

规范 状态 注释
{{SpecName('DOM WHATWG', '#dom-range-deletecontents', 'Range.deleteContents()')}} {{Spec2('DOM WHATWG')}} No change.
{{SpecName('DOM2 Traversal_Range', 'ranges.html#Level2-Range-method-deleteContents', 'Range.deleteContents()')}} {{Spec2('DOM2 Traversal_Range')}} Initial specification.

浏览器兼容性

{{CompatibilityTable}}

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatGeckoDesktop("1.0")}} 9.0 9.0 {{CompatVersionUnknown}}
Feature Android Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatGeckoMobile("1.0")}} 9.0 9.0 {{CompatVersionUnknown}}

参考