HTML DOM教程 19-HTML DOM Button 对象
生活随笔
收集整理的這篇文章主要介紹了
HTML DOM教程 19-HTML DOM Button 对象
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
HTML DOM教程 19-HTML DOM Button 對象
?
1:Button 對象
Button 對象代表一個按鈕。
在 HTML 文檔中 <button> 標簽每出現一次,Button 對象就會被創建。
2:Button 對象的屬性
| accessKey | 設置或返回訪問某個按鈕的快捷鍵。 | 6 | 1 | 9 | Yes |
| disabled | 設置或返回是否禁用按鈕。 | 6 | 1 | 9 | Yes |
| form | 返回對包含按鈕的表單的引用。 | 6 | 1 | 9 | Yes |
| id | 設置或返回按鈕的 id。 | 6 | 1 | 9 | Yes |
| name | 設置或返回按鈕的名稱。 | 6 | 1 | 9 | Yes |
| tabIndex | 設置或返回按鈕的 Tab 鍵控制次序。 | 6 | 1 | 9 | Yes |
| type | 返回按鈕的表單類型。 | 6 | 1 | 9 | Yes |
| value | 設置或返回顯示在按鈕上的文本。 | 6 | 1 | 9 | Yes |
3:標準屬性
| className | Sets or returns the class attribute of an element | 5 | 1 | 9 | Yes |
| dir | Sets or returns the direction of text | 5 | 1 | 9 | Yes |
| lang | Sets or returns the language code for an element | 5 | 1 | 9 | Yes |
| title | Sets or returns an element's advisory title | 5 | 1 | 9 | Yes |
? 4:className 屬性
本例展示了兩種獲得 <body> 元素的 class 屬性的方法:
<html><body id="myid" class="mystyle">
<script type="text/javascript">
x=document.getElementsByTagName('body')[0];
document.write("Body CSS class: " + x.className);
document.write("<br />");
document.write("An alternate way: ");
document.write(document.getElementById('myid').className);
</script>
</body>
</html>
輸出:
Body CSS class: mystyleAn alternate way: mystyle
5:其他屬性演示
<html>
<script type="text/javascript">
function alertId()
{
var txt="Id: " + document.getElementById("myButton").id
txt=txt + ", type: " + document.getElementById("myButton").type
txt=txt + ", type: " + document.getElementById("myButton").form
?
document.getElementById("myButton").disabled=true
}
</script>
</head>
<body>
<form>
<button id="myButton" onClick="alertId()">請點擊我!</button>
</form>
</body>
??? </html>
總結
以上是生活随笔為你收集整理的HTML DOM教程 19-HTML DOM Button 对象的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 很基本的权限功能小结
- 下一篇: 编程寓言:两位新手正讨论常用快捷键,路边