zoukankan      html  css  js  c++  java
  • JQuery移除事件

    移除事件

        unbind(type [,data])     //data是要移除的函数

        $('#btn').unbind("click"); //移除click

        $('#btn').unbind(); //移除所有 
        对于只需要触发一次的,随后就要立即解除绑定的情况,用one()

        $('#btn').one("click",function(){.......}); 
        模拟操作

        可以用trigger()方法完成模拟操作。

        $('#btn').trigger("click"); 
        $('#btn').click();

        触发自定义事件

        $('#btn').bind("myclick",function(){....});

        $('#btn').trigger("myclick"); 
        传递数据

        trigger(type [,data])

        $('#btn').bind("myclick",function(event,message1,message2){...........});

        $('#btn').trigger("myclick",["传给message1","传给message2"]);

        执行默认操作 
        $("input").trigger("focus");

            //不仅会触发input元素绑定的focus事件,还会触发默认操作——得到焦点。

        $("input").triggerHandler("focus");

            //只触发绑定事件,不执行浏览器默认操作

        其他用法

        绑定多个事件类型

        $("div").bind("mouseover mouseout",function(){.....});

        添加事件命名空间

        $("div").bind("click.plugin",function(){......});

        在所绑定的世界类型后面添加命名空间,这样在删除事件时只需要指定命名空间即可。

            $("div").unbind(".plugin");   //删除空间内的事件

        $("div").trigger("click!"); //触发所以不包含在命名空间中的click方法

        如果包含在命名空间的也要触发:

            $("div").trigger("click");

    另外摘录

    ================================================
    $('div').bind('click', RecommandProduct);//为div绑定RecommandProduct 函数
    $('div').unbind('click', RecommandProduct);//取消RecommandProduct 函数

    坚持下去就能成功
  • 相关阅读:
    Leetcode Reverse Words in a String
    topcoder SRM 619 DIV2 GoodCompanyDivTwo
    topcoder SRM 618 DIV2 MovingRooksDiv2
    topcoder SRM 618 DIV2 WritingWords
    topcoder SRM 618 DIV2 LongWordsDiv2
    Zepto Code Rush 2014 A. Feed with Candy
    Zepto Code Rush 2014 B
    Codeforces Round #245 (Div. 2) B
    Codeforces Round #245 (Div. 2) A
    Codeforces Round #247 (Div. 2) B
  • 原文地址:https://www.cnblogs.com/suoking/p/5417011.html
Copyright © 2011-2022 走看看