zoukankan      html  css  js  c++  java
  • DOM—addEventListener() & removeEventListener()

    DOM EventListener:
    方法:
    addEventListener():用于向指定元素添加事件句柄
    removeEventListener():移除方法添加的事件句柄

    <body>
        <button id="btn">按钮</button>
        <script>
            //放在button标签后面,放在前面,无法获取标签
            var x = document.getElementById("btn");
            x.addEventListener("click", hello);//添加句柄
            x.addEventListener("click", world);//为事件添加多个句柄,不会被覆盖
            x.removeEventListener("click", hello);//移除句柄
            function hello() {
                alert("Hello");
            }
            function world() {
                alert("World");
            }
        </script>
    </body>
  • 相关阅读:
    SpringBoot
    SpringBoot
    MySQL
    Database
    Database
    MySQL
    Debug
    《mysql必知必会》学习_第18章
    C#中访问私有成员
    精彩语录收集
  • 原文地址:https://www.cnblogs.com/feile/p/5449593.html
Copyright © 2011-2022 走看看