js toggle事件

参数:
even (Function): 第奇数次点击时要执行的函数。 
odd (Function): 第偶数次点击时要执行的函数。 
示例:
$("p").toggle(function(){
          $(this).addClass("selected");   
        },function(){
         $(this).removeClass("selected"); 
}); 

toggle(even,odd) 
Toggle between two function calls every other click. Whenever a matched element is clicked, the first specified function is fired, when clicked again, the second is fired. All subsequent clicks continue to rotate through the two functions. 

Jquery1.9.1中 toggle(fn1,fn2...)方法 可实现点击一个元素来执行指定函数。此方法被删除以减少混乱和提高潜在的模块化程度。只保留了显示和隐藏的功能!

Jquery1.9版本后删除 奇数/偶数次点击继续函数。

今天用到记录一下,用下面方法代替。

var isHidden = $("#id").is(":hidden");
if(isHidden){
$("#id  a").css("background-position","-23px -3px");
}else{
$("#id a").css("background-position","-3px -3px");
}

原文地址:https://www.cnblogs.com/chenweichu/p/5481346.html