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