aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/element/setattributenodens
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/element/setattributenodens
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/api/element/setattributenodens')
-rw-r--r--files/zh-cn/web/api/element/setattributenodens/index.html47
1 files changed, 47 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/element/setattributenodens/index.html b/files/zh-cn/web/api/element/setattributenodens/index.html
new file mode 100644
index 0000000000..9e791e1f0c
--- /dev/null
+++ b/files/zh-cn/web/api/element/setattributenodens/index.html
@@ -0,0 +1,47 @@
+---
+title: Element.setAttributeNodeNS()
+slug: Web/API/Element/setAttributeNodeNS
+translation_of: Web/API/Element/setAttributeNodeNS
+---
+<p>{{ APIRef("DOM") }}</p>
+
+<p><code>setAttributeNodeNS</code> 可以给一个元素添加一个新的命名空间的属性节点.</p>
+
+<p>                                                                                                                               (如果对中文有疑惑,请直接阅读原文)</p>
+
+<h2 id="Syntax" name="Syntax">Syntax                                                                 </h2>
+
+<pre class="eval"><em>replacedAttr</em> = element.setAttributeNodeNS(<em>attributeNode</em>)
+</pre>
+
+<ul>
+ <li><code>replacedAttr</code> 是被替换的节点, 如果存在, 由此函数返回.</li>
+ <li><code>attributeNode</code> 是一个属性节点.</li>
+</ul>
+
+<h2 id="Example" name="Example">Example</h2>
+
+<pre>// &lt;div id="one" xmlns:myNS="http://www.mozilla.org/ns/specialspace"
+ myNS:special-align="utterleft"&gt;one&lt;/div&gt;
+// &lt;div id="two"&gt;two&lt;/div&gt;
+
+
+var myns = "http://www.mozilla.org/ns/specialspace";
+var d1 = document.getElementById("one");
+var d2 = document.getElementById("two");
+var a = d1.getAttributeNodeNS(myns, "special-align");
+d2.setAttributeNodeNS(a.cloneNode(true));
+alert(d2.attributes[1].value) // returns: `utterleft'
+</pre>
+
+<h2 id="Notes" name="Notes">Notes</h2>
+
+<p>如果指定的属性在元素上存在, 接着此属性被新的属性替换的话被替换的属性会被返回.</p>
+
+<p>注意:如果你尝试设置的时候没有克隆那个节点,Mozia会抛出一个NS_ERROR_DOM_INUSE_ATTRIBUTE_ERR :"Attribute already in use" 错误, 因为DOM需要克隆属性之后才能重复使用( 不像其他节点一样可以被删除 ) 。</p>
+
+<p>{{ DOMAttributeMethods() }}</p>
+
+<h2 id="Specification" name="Specification">Specification</h2>
+
+<p><a class="external" href="http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-ElSetAtNodeNS">DOM Level 2 Core: setAttributeNodeNS</a></p>