1
<p id="demo">单击按钮查找按钮是否有onclick属性</p>
2
<button onclick="myFunction()">点我</button>
3
<script>
4
function myFunction() {
5
var btn = document.getElementsByTagName("BUTTON")[0];
6
var x = document.getElementById("demo");
7
x.innerHTML = btn.getAttributeNode("onclick").specified;
8
}
9
</script>