为什么我无法在 if 表达式中调用 Jquery 函数
$("#btn1").click(function(){
//CheckMyWeight is called Perfectly here and not in the if loop expression
if ($("#frm1").validationEngine({returnIsValid:true}) && CheckMyWeight() && a === b) {
}});
为什么我无法在 if 循环表达式中调用“CheckMyWeight()”,但我能够完美调用 在“#btn1”函数之后。
$("#btn1").click(function(){
//CheckMyWeight is called Perfectly here and not in the if loop expression
if ($("#frm1").validationEngine({returnIsValid:true}) && CheckMyWeight() && a === b) {
}});
why i am not able to call the "CheckMyWeight()" in the if loop expression and i am able to call perfectly
after the "#btn1" function.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果
&&
的左侧返回 false,则不会评估右侧。 (因为整个表达式不可能为真)这称为短路。
如果您想始终调用这两个函数,则应该在条件之外调用它们并将结果分配给变量,并留下注释解释原因:
还有其他解决方法,但它们隐藏了代码的意图。
If the left side of the
&&
returns falsy, the right side won't be evaluated. (since the whole expression cannot possibly be true)This is called short-circuiting.
If you want to always call both functions, you should call them outside the condition and assign the results to variables, and leave a comment explaining why:
There are other workarounds, but they hide the intention of the code.
下面是一个小程序,用于测试您是否可以在 if 循环表达式中调用“CheckMyWeight()”。它的工作原理是,问题在于 $("#frm1").validationEngine({returnIsValid:true} 尝试通过打破条件。
The below is a small program to test whether u can call the "CheckMyWeight()" in the if loop expression .Its working so the problem is with $("#frm1").validationEngine({returnIsValid:true} try to work by breaking the conditions.