Since the jQuery .toggle event method is deprecated. What are we suppose to use to simulate this event (alternate clicks)?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Add this outside of document.ready
$.fn.clicktoggle = function(a, b) { return this.each(function() { var clicked = false; $(this).click(function() { if (clicked) { clicked = false; return b.apply(this, arguments); } clicked = true; return a.apply(this, arguments); }); }); }; then use the following to replicate the .toggle functionality:
$("#mydiv").clicktoggle(functionA,functionB); Found on the JQuery Forums
回答2:
var i = 0; $('button').click(function() { if (i == 0){ $('div').css({background: 'red'}) i++; } else { $('div').css({background: 'yellow'}) i = 0; } });