blob: 50e8e7b1884ba96bf5ce9182bcadee011bbb6a4e (
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
38
39
40
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><button id="foo" label="Click Me" oncommand="doSomething()"/>
<script>
function doSomething(){
var myButton = document.getElementById('foo');
myButton.setAttribute('label','The button was pressed');
}
</script>
</pre>
<p>一个更加抽象的版本</p>
<pre><button id="foo" label="Click Me" oncommand="setWidgetLabel(this, 'I was pressed')"/>
<script>
function setWidgetLabel(idName, newCaption){
document.getElementById( idName.id ).setAttribute('label',newCaption)
}
</script>
</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>
|