From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../web/api/element/setattributenodens/index.html | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 files/zh-cn/web/api/element/setattributenodens/index.html (limited to 'files/zh-cn/web/api/element/setattributenodens/index.html') 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 +--- +

{{ APIRef("DOM") }}

+ +

setAttributeNodeNS 可以给一个元素添加一个新的命名空间的属性节点.

+ +

                                                                                                                               (如果对中文有疑惑,请直接阅读原文)

+ +

Syntax                                                                 

+ +
replacedAttr = element.setAttributeNodeNS(attributeNode)
+
+ + + +

Example

+ +
// <div id="one" xmlns:myNS="http://www.mozilla.org/ns/specialspace"
+            myNS:special-align="utterleft">one</div>
+// <div id="two">two</div>
+
+
+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'
+
+ +

Notes

+ +

如果指定的属性在元素上存在, 接着此属性被新的属性替换的话被替换的属性会被返回.

+ +

注意:如果你尝试设置的时候没有克隆那个节点,Mozia会抛出一个NS_ERROR_DOM_INUSE_ATTRIBUTE_ERR :"Attribute already in use" 错误, 因为DOM需要克隆属性之后才能重复使用( 不像其他节点一样可以被删除 ) 。

+ +

{{ DOMAttributeMethods() }}

+ +

Specification

+ +

DOM Level 2 Core: setAttributeNodeNS

-- cgit v1.2.3-54-g00ecf