如何在 jQuery 中跳转或逃逸链
如何在 jQuery 中跳跃或逃逸链。
例如。
$("h3").click(function(){
//doSomething
if(~~)
// in this case, escape chain(A and B function will be not work)
else if(~~)
// in this case, jump to B case(A function will be not work)
})
.bind(A, function(){
do A case.
})
.bind(B, function(){
do B case.
});
是否可以?
How to jumping or escape chain in jQuery.
for example.
$("h3").click(function(){
//doSomething
if(~~)
// in this case, escape chain(A and B function will be not work)
else if(~~)
// in this case, jump to B case(A function will be not work)
})
.bind(A, function(){
do A case.
})
.bind(B, function(){
do B case.
});
is it possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
单击处理程序中的代码在单击实际发生之前不会执行,而绑定调用是在应用单击处理程序后立即处理的。看起来您想要的是各种处理程序的条件执行。您可以通过在原始单击处理程序中设置元素上的数据,然后检查后续处理程序中的状态来实现此目的,但最好将它们创建为独立函数,然后根据需要从单击处理程序中调用它们。
The code in the click handler isn't executed until the click actually happens, while the bind calls are handled right after the click handler is applied. It looks like what you want is conditional execution of the various handlers. You could achieve that by setting data on the element in the original click handler, then checking the state in the subsequent handlers, but it would probably be better to create them as standalone functions and simply call them from the single click handler as appropriate.
如果 A 和 B 实际上只是函数,其中之一应该在单击时调用,请执行以下操作:
但是,您的问题并不完全清楚。
If A and B are actually just functions, one of which should be called on click, do:
However, your question is not completely clear.
要结束你的链,你可以使用 jQuery
.end()
方法;但在这种情况下,您有一个条件,并且应该为每个条件运行两个不同的代码。因此,您可以在您的条件下使用 jQuery$(this)
来引用单击的内容并根据您的条件运行代码:To end your chain you can use jQuery
.end()
method; But in this case you have a condition and two different code should run for each conditions. So you can use jQuery$(this)
under your condition to refer to what is clicked and run the code based on your condition: