开发者

Trigger second function in toggle()

开发者 https://www.devze.com 2023-01-10 01:29 出处:网络
I开发者_JS百科s there a way I can call the second function intoggle(function(){},function(){})You could skip the toggle to the next function, if you really wanted to I suppose, for example:

I开发者_JS百科s there a way I can call the second function in toggle(function(){},function(){})


You could skip the toggle to the next function, if you really wanted to I suppose, for example:

$("div").toggle(function() {
    alert("First");
}, function() {
    alert("Second");
})​;

Then you can manually advance the .toggle() function array (without calling the first function), like this:

$("div").data('lastToggle' + $("div").data().events.click[0].handler.guid, 1);

Then just click the element or $("div").click(), etc, and it'll fire the second function.

You can give it a try here, note that this only works in jQuery 1.4+ and is really just to show it's possible. You should however either bind them in reverse order, or give the second argument a named function as the other answers suggest.


how about

toggle(function(){ callFunctionOne(); callFunctionTwo(); });


I suggest such solution:

toggle(function(){},secondFunction);

function secondFunction() {}

And now you can call it how you want :)

0

精彩评论

暂无评论...
验证码 换一张
取 消