From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../zh-cn/mozilla/tech/xul/attribute/id/index.html | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 files/zh-cn/mozilla/tech/xul/attribute/id/index.html (limited to 'files/zh-cn/mozilla/tech/xul/attribute/id') 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 +--- +
+ « XUL Reference home
+
+
+ id
+
+ 类型: 元素的ID,在主窗口中必须唯一
+
+ 一个唯一的标识一边开发者能够定义. 你可以使用方法 getElementById() 或者其他 DOM 的函数并在样式表中添加对元素的引用。
+
+
+

示例

+
<button id="foo" label="Click Me" oncommand="doSomething()"/>
+
+<script>
+function doSomething(){
+    var myButton = document.getElementById('foo');
+    myButton.setAttribute('label','The button was pressed');
+}
+</script>
+
+

一个更加抽象的版本

+
<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>
+
+

同样,这里还有一些资料

+

name

+
+

-- cgit v1.2.3-54-g00ecf