aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/element/setattributens/index.html
blob: c4ceae36dfc7c7e1e7b51c491d88fad66043aeff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
---
title: Element.setAttributeNS()
slug: Web/API/Element/setAttributeNS
tags:
  - Element.setAttributeNS()
  - SVG
  - 'http://svgjs.com/'
translation_of: Web/API/Element/setAttributeNS
---
<p>{{ APIRef("DOM") }}</p>

<p><code>setAttributeNS</code> 添加一个新属性或更改具有给定命名空间和名称的一个属性的值。</p>

<h2 id="Syntax" name="Syntax">句法</h2>

<pre class="eval"><em>element</em>.setAttributeNS(<em>namespace</em>,<em>name</em>,<em>value</em>)
</pre>

<ul>
 <li><code>namespace</code> 是指定属性的命名空间的一个字符串。</li>
 <li><code>name</code> 是标识要设置的属性的一个字符串。</li>
 <li><code>value</code> 是新属性的所需字符串值。</li>
</ul>

<h2 id="Example" name="Example">范例</h2>

<pre class="eval">let d = document.getElementById("d1");
d.setAttributeNS("<span class="nowiki">http://www.mozilla.org/ns/specialspace</span>", "align", "center");
</pre>

<h2 id="Notes" name="Notes">注释</h2>

<p>{{ DOMAttributeMethods() }}</p>

<h2 id="Specification" name="Specification">规范</h2>

<p><a class="external" href="http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-ElSetAttrNS">DOM Level 2 Core: setAttributeNS</a></p>