diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/element/removeattribute | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/api/element/removeattribute')
-rw-r--r-- | files/zh-cn/web/api/element/removeattribute/index.html | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/element/removeattribute/index.html b/files/zh-cn/web/api/element/removeattribute/index.html new file mode 100644 index 0000000000..92a3d3844b --- /dev/null +++ b/files/zh-cn/web/api/element/removeattribute/index.html @@ -0,0 +1,54 @@ +--- +title: Element.removeAttribute() +slug: Web/API/Element/removeAttribute +tags: + - 属性 + - 方法 +translation_of: Web/API/Element/removeAttribute +--- +<p>{{ APIRef("DOM") }}</p> + +<p><span class="seoSummary">{{domxref("Element", "元素")}}方法 <code><strong>removeAttribute()</strong></code> 从指定的元素中删除一个属性。</span></p> + +<h3 id="语法">语法</h3> + +<pre class="syntaxbox notranslate"><em>element</em>.removeAttribute(<em>attrName</em>); +</pre> + +<h3 id="参数">参数</h3> + +<dl> + <dt><font face="consolas, Liberation Mono, courier, monospace"><span style="background-color: rgba(220, 220, 220, 0.5);">属性名</span></font></dt> + <dd>{{domxref("DOMString")}}指定要从元素中移除的属性的名称。如果指定的属性不存在,则removeAttribute()返回,但不会生成错误。</dd> +</dl> + +<h3 id="返回值">返回值</h3> + +<p>IE 返回boolean类型值,其他返回undefined</p> + +<div class="note"> +<p><strong>注意:</strong>因为 <code>removeAttribute()</code> 不会返回任何有效值,你不能使用链式方法(连续使用方法,例如 <code>document.body.removeAttribute("first").removeAttribute("second")…</code>)连续移除多个属性。</p> +</div> + +<h2 id="Notes" name="Notes">使用说明</h2> + +<p>若要彻底移除一个属性的效果,应当使用 <code>removeAttribute()</code>,而不是使用 {{domxref("Element.setAttribute", "setAttribute()")}} 将属性值设置为 <code>null</code>。对于许多属性,如果仅将其值设为 <code>null</code>,这不会造达成和预期一样的效果。</p> + +<p>{{ DOMAttributeMethods() }}</p> + +<h2 id="例子">例子</h2> + +<pre class="brush: js notranslate">// Given: <div id="div1" align="left" width="200px"> +document.getElementById("div1").removeAttribute("align"); +// Now: <div id="div1" width="200px"> +</pre> + +<h2 id="规范">规范</h2> + +<p><a class="external" href="http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-6D6AC0F9">DOM Level 2 Core: removeAttribute</a> (introduced in <a class="external" href="http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#method-removeAttribute">DOM Level 1 Core</a>)</p> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + + + +<p>{{Compat("api.Element.removeAttribute")}}</p> |