[英]jQuery Toggle — One Function One Click Then Another
Here's what I would like to do in pseudocode form. 这是我想以伪代码形式进行的操作。
Bind Two Functions to Click Event
On 1st/Odd Clicks Do FunctionA()
On 2nd/Even Clicks Do FunctionB()
The .toggle() function seems to not be designed for this. .toggle()函数似乎并非为此设计的。
I'm sure this exists in jQuery but my googling hasn't resulted in anything. 我确定这存在于jQuery中,但是我的谷歌搜索没有任何结果。 :)
:)
I don't see how this isn't exactly what toggle
is designed for... 我不明白这与
toggle
功能设计的目的不完全相同 ...
$('#someEl').toggle(FunctionA, FunctionB);
You may be confused by the other toggle
function that exists in jQuery, which won't be called if you pass functions as the arguments. 您可能会对jQuery中存在的另一个
toggle
功能感到困惑,如果您将功能作为参数传递,则不会被调用。
var i=1;
$(".a").click (function () {if (i%2!=0) FunctionA();i++;});
$(".a").click (function () {if (i%2==0) FunctionB();i++;});
You just need to ask Google the right question ;) 您只需要问Google正确的问题即可;)
$(selector).toggle(function(),function(),function(),...)
http://www.w3schools.com/jquery/eff_toggle.asp http://www.w3schools.com/jquery/eff_toggle.asp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.