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()"/>

  • 相关阅读:
    Timer控件和MenuStrip控件
    ListView的使用
    TreeView使用
    打包Apk之Could not download groovy-all.jar (org.codehaus.groovy:groovy-all:2.4.15)以及appIcon报错
    轮播图的组合控件、自定义属性、自动轮播
    【LeetCode】080. Remove Duplicates from Sorted Array II
    【阿里巴巴】2018秋招研发工程师笔试题
    【Facebook】等差子序列个数
    【LeetCode】137. Single Number II
    【Sublime Text 3】编译环境
  • 原文地址:https://www.cnblogs.com/java-llp/p/10811414.html
Copyright © 2011-2022 走看看