<html>
<body>
<p id="demo">请点击按钮来查看 button 元素是否拥有 onclick 属性。</p>
<button onclick="myFunction()">试一下</button>
<script>
function myFunction()
{
var btn=document.getElementsByTagName("BUTTON")[0];
var x=document.getElementById("demo");
x.innerHTML=btn.hasAttribute("onclick");
}
</script>
<p>Internet Explorer 8 以及更早的版本不支持该方法。</p>
</body>
</html>