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