触发toggle()中的第二个函数

发布于 2024-09-12 03:17:58 字数 71 浏览 1 评论 0原文

有没有办法可以调用 toggle(function(){},function(){}) 中的第二个函数

Is there a way I can call the second function in toggle(function(){},function(){})

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

高速公鹿 2024-09-19 03:17:58

如果您确实想要的话,您可以跳过切换到下一个功能,例如:

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

然后您可以手动前进 .toggle() 函数数组(调用第一个函数),如下所示:

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

然后只需单击该元素或 < code>$("div").click() 等,它将触发第二个函数。

您可以在这里尝试一下,请注意,这仅适用于 jQuery 1.4+,而且实际上只是为了表明这是可能的。但是,您应该以相反的顺序绑定它们,或者按照其他答案的建议为第二个参数指定一个命名函数。

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.

夏日落 2024-09-19 03:17:58

怎么样

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

how about

toggle(function(){ callFunctionOne(); callFunctionTwo(); });
泅人 2024-09-19 03:17:58

我建议这样的解决方案:

toggle(function(){},secondFunction);

function secondFunction() {}

现在你可以按照你想要的方式称呼它:)

I suggest such solution:

toggle(function(){},secondFunction);

function secondFunction() {}

And now you can call it how you want :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文