xxxxxxxxxx
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
</head>
<body>
<p id="demo">单击按钮查看按钮元素有多少属性</p>
<button onclick="myFunction()">点我</button>
<script>
function myFunction(){
var a=document.getElementsByTagName("BUTTON")[0].attributes;
var x=document.getElementById("demo");
x.innerHTML=a.length;
}
</script>
<p>结果将是1 (按钮元素的onclick属性)。</p>
<p><strong>Note:</strong> In Internet Explorer 8 及更早的版本,attributes属性将返回所有元素的属性集合,并且在这个例子中,显示比1更大的数。</p>
</body>
</html>