aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/mozilla/tech/xul/attribute/id
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/mozilla/tech/xul/attribute/id
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/mozilla/tech/xul/attribute/id')
-rw-r--r--files/zh-cn/mozilla/tech/xul/attribute/id/index.html41
1 files changed, 41 insertions, 0 deletions
diff --git a/files/zh-cn/mozilla/tech/xul/attribute/id/index.html b/files/zh-cn/mozilla/tech/xul/attribute/id/index.html
new file mode 100644
index 0000000000..50e8e7b188
--- /dev/null
+++ b/files/zh-cn/mozilla/tech/xul/attribute/id/index.html
@@ -0,0 +1,41 @@
+---
+title: id
+slug: Mozilla/Tech/XUL/Attribute/id
+tags:
+ - XUL Attributes
+translation_of: Archive/Mozilla/XUL/Attribute/id
+---
+<div class="noinclude">
+ <span class="breadcrumbs xulRefAttr_breadcrumbs">« <a href="/zh-CN/docs/XUL_Reference">XUL Reference home</a></span></div>
+<dl>
+ <dt>
+ <code id="a-id"><a href="https://developer.mozilla.org/zh-CN/docs/Mozilla/Tech/XUL/Attribute/id">id</a></code></dt>
+ <dd>
+ 类型: <em>元素的ID,在主窗口中必须唯一</em></dd>
+ <dd>
+ 一个唯一的标识一边开发者能够定义. 你可以使用方法 <code><a href="/cn/DOM/document.getElementById" title="cn/DOM/document.getElementById">getElementById()</a></code> 或者其他 DOM 的函数并在样式表中添加对元素的引用。</dd>
+</dl>
+<div class="noinclude">
+ <h4 id="Example" name="Example">示例</h4>
+ <pre>&lt;button id="foo" label="Click Me" oncommand="doSomething()"/&gt;
+
+&lt;script&gt;
+function doSomething(){
+ var myButton = document.getElementById('foo');
+ myButton.setAttribute('label','The button was pressed');
+}
+&lt;/script&gt;
+</pre>
+ <p>一个更加抽象的版本</p>
+ <pre>&lt;button id="foo" label="Click Me" oncommand="setWidgetLabel(this, 'I was pressed')"/&gt;
+&lt;script&gt;
+function setWidgetLabel(idName, newCaption){
+ document.getElementById( idName.id ).setAttribute('label',newCaption)
+}
+
+&lt;/script&gt;
+</pre>
+ <h4 id="See_also" name="See_also">同样,这里还有一些资料</h4>
+ <p><code id="a-name"><a href="https://developer.mozilla.org/zh-CN/docs/Mozilla/Tech/XUL/Attribute/name">name</a></code></p>
+</div>
+<p></p>