jQuery API | 返回首页目录 | jQuery API 中英文对照版 |
toggle(even, odd) |
toggle(even,odd)
每次点击时切换要调用的函数。 如果点击了一个匹配的元素,则触发指定的第一个函数,当再次点击同一元素时,则触发指定的第二个函数。随后的每次点击都重复对这两个函数的轮番调用。 可以使用unbind("click")来删除。 返回值:jQuery 参数:
示例: $("p").toggle(function(){ $(this).addClass("selected"); },function(){ $(this).removeClass("selected"); }); 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
Example: $("p").toggle(function(){ $(this).addClass("selected"); },function(){ $(this).removeClass("selected"); }); |