<!DOCTYPE html> <!--JS事件详解-事件处理--> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> </head> <body> <div id="div01"> <button id="btn01" οnclick="demo01()">按钮01</button> <br/> <button id="btn02">按钮02</button> <br/> </div> <!--直接调方法--> <script> function demo01(){ alert("点击事件"); } </script> <!--dom二级事件处理程序,就是前面写的句柄--> <script> var x = document.getElementById("btn02"); x.addEventListener("click", method01); function method01() { alert("句柄01") }//事件不会覆盖 x.addEventListener("click", method02); function method02() { alert("句柄02") } </script> </body> </html>
js基础精华04
最新推荐文章于 2024-05-11 10:06:58 发布