zoukankan      html  css  js  c++  java
  • js off bind unbind delegate undelegate绑定解绑操作,其中off可以解绑任意js事件

     

    /*绑定多个事件

    $(function(){ 

    $("div").delegate("#a,#b",{"click":function(){

    alert(1)

    }

    ,"mouseover":function(){

    $(this).before(1)

    }

    })})

    $(function(){ 

          $("div").delegate("#a,#b","click mouseover",function(){

       alert(1)

      })

            })

    $(document).ready(function(e) {

             $("#a").on({

    "click":function(){

    alert(1)},"mouseover":function(){alert(2)}

    })

          });

          function un(){ 

        $("div").undelegate("mouseover")

          }

       

        $(document).ready(function(e) {

         $("#a,#b").delegate(this,"click",function(){

      alert(1)

    })

        });

         //单个解除或多个off

         function un(){ 

       $("#a,#b").off("click")   or $("#a").unbind("click") or $("#a").off("click")$("#a").off("click") 事 off可以解绑delegate bind on等事件

         }

        */

         

    /* function test(event){

       alert(event.data.data)

    }

         $(document).ready(function(e) {

    $("#a").on("click",{data:"1"},test)

         });

    $(function(){

        $("#a").on("自定义事件",function(event,data){

      alert(data)

    }) 

      

      $("#a").trigger("自定义事件","231")

         })

    $(function(){

    $("#a").mouseover(function(){

    alert(1)

    })

    })

      function un(){ 

           $("#a").off("mouseover")   

         }*/

    </script>

    </head>

    <body>

      <div>

         <span id="a" style="display:block; 20px; height:20px; background-color:#F00; color:#0F0; text-align:center;" >1</span> <br/> <br/>

            <span id="b" style="display:block; 20px; height:20px; background-color:#F00; color:#0F0; text-align:center;">2</span> <br/> <br/>

              <span id="c" style="display:block; 20px; height:20px; background-color:#F00; color:#0F0; text-align:center;">3</span> <br/> <br/>

               </div>

                   <input type="button" value="移除事件"  onclick="un()"/>


    /*绑定多个事件$(function(){ $("div").delegate("#a,#b",{"click":function(){alert(1)},"mouseover":function(){$(this).before(1)}})}) $(function(){       $("div").delegate("#a,#b","click mouseover",function(){   alert(1)  })        })$(document).ready(function(e) {         $("#a").on({"click":function(){alert(1)},"mouseover":function(){alert(2)}})      });       function un(){     $("div").undelegate("mouseover")      }       $(document).ready(function(e) {     $("#a,#b").delegate(this,"click",function(){  alert(1)})    });
         //单个解除或多个off     function un(){    $("#a,#b").off("click")   or $("#a").unbind("click") or $("#a").off("click")$("#a").off("click") 事 off可以解绑delegate bind on等事件     }    */     /* function test(event){   alert(event.data.data) }     $(document).ready(function(e) { $("#a").on("click",{data:"1"},test)     });   $(function(){    $("#a").on("自定义事件",function(event,data){  alert(data)})     $("#a").trigger("自定义事件","231")     })  $(function(){ $("#a").mouseover(function(){ alert(1) }) })  function un(){        $("#a").off("mouseover")        }*/  </script>
    </head>
    <body>  <div>     <span id="a" style="display:block; 20px; height:20px; background-color:#F00; color:#0F0; text-align:center;" >1</span> <br/> <br/>        <span id="b" style="display:block; 20px; height:20px; background-color:#F00; color:#0F0; text-align:center;">2</span> <br/> <br/>          <span id="c" style="display:block; 20px; height:20px; background-color:#F00; color:#0F0; text-align:center;">3</span> <br/> <br/>           </div>               <input type="button" value="移除事件"  onclick="un()"/>

  • 相关阅读:
    微擎 关注发送推荐消息
    修改 processor.php 文件,监听用户对该应用的消息
    微擎返回图文信息
    微擎客服消息发送的函数
    mui 底部导航栏的实现
    两张表的关联查询
    微擎 截取字符串
    webStorm中NodeJs 没有智能提示
    OpenCV 实现自己的线性滤波器
    OpenCV 基本的阈值操作
  • 原文地址:https://www.cnblogs.com/java-llp/p/10811414.html
Copyright © 2011-2022 走看看