案例:javascript案例     状态:可编辑再运行    进入竖版
 运行结果 
x
 
1
<!DOCTYPE html>
2
<html>
3
<body>
4
5
<p id="demo">点击按钮来查看 button 元素拥有的属性数:</p>
6
7
<button onclick="myFunction()">试一下</button>
8
9
<script>
10
function myFunction()
11
{
12
var a=document.getElementsByTagName("BUTTON")[0].attributes;
13
var x=document.getElementById("demo");  
14
x.innerHTML=a.length;
15
}
16
</script>
17
18
<p>结果是 1(button 元素的 onclick 属性)。</p>
19
20
</body>
21
</html>
22
23