JavaScript基础----22Javascript-DOM EventListener

来源:互联网 发布:手机网络打印机 编辑:程序博客网 时间:2024/06/05 15:13
<!DOCTYPE html><!--Javascript-DOM EventListener--><html><head lang="en">    <meta charset="UTF-8">    <title></title></head><body><!--<button id="btn">按钮</button>--><!--句柄的作用 多个事件不会覆盖--><!--<script>-->    <!--document.getElementById("btn").addEventListener("click",function demo(){-->        <!--alert("hello")-->    <!--});--><!--</script>--><!--句柄的作用 多个事件不会覆盖有点像java中的匿名内部类--><button id="btn">按钮</button><script>    var myjubing=document.getElementById("btn");    myjubing.addEventListener("click",hello);  //添加句柄    myjubing.addEventListener("click",world);    myjubing.removeEventListener("click",hello);//移出句柄    function hello(){        alert("hello");    }    function world(){        alert("world");    };</script></body></html>
0 0
原创粉丝点击