jQuery API 返回首页目录 | jQuery API 中英文对照版
toggle(even, odd)
toggle(even,odd)

每次点击时切换要调用的函数。

如果点击了一个匹配的元素,则触发指定的第一个函数,当再次点击同一元素时,则触发指定的第二个函数。随后的每次点击都重复对这两个函数的轮番调用。 可以使用unbind("click")来删除。

返回值:jQuery

参数:

  • 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.

Use unbind("click") to remove.

Return value: jQuery
Parameters:

  • even (Function): The function to execute on every even click.
  • odd (Function): The function to execute on every odd click.

Example:

 $("p").toggle(function(){
     $(this).addClass("selected");   
 },function(){
     $(this).removeClass("selected");  
 });  
相关链接
asp之家 | jQuery官方网站 | jQuery中文网 | 电子书作者网站 | 电子书作者blog