<!doctype html><html><head> <meta charset="UTF-8"> <title>跨游览器封装函数</title></head><body> <h1 onclick="alert('这是html事件绑定方式1')">html事件绑定方式1</h1> <h1 onclick="f1()">html事件绑定方式2</h1> <h2 onclick="f1()">dom0级事件绑定方式</h2> <script type="text/javascript"> function f1(){ alert('这是html事件绑定方式2'); } var h2 = document.getElementsByTagName('h2'); console.log(h2[0]); h2[0].onclick = function(){ alert('这是dom0级事件绑定方式'); } h2[0].onclick = "alert('这是dom0级事件绑定方式')"; </script> </body></html>
添加回答
举报
0/150
提交
取消