替代jquery1.9版本以前的toggle事件函数(开关)

以上文章为转载自http://blog.sina.com.cn/s/blog_50042fab0101c7a9.html

var flag=1;
    $(".selector").click(function(){
        if(flag==1){
            //执行方法;
            flag=0;
        }else{
            //执行方法;
            flag=1;
        }

或者外接函数,例如

toggle(objs) {
    $(objs).each(function(){
        if ($(this).is(':hidden')) $(this).show(); else $(this).hide();
    });
}

第一种方法也是开关 的很好的体现。

原文地址:https://www.cnblogs.com/beileixinqing/p/6149232.html