简体   繁体   English

我在解释Java运算符的不平等时遇到一些问题

[英]I am having some issues interpreting inequalities with Javascript Operators

For my little app I need to do some very simple math... But for some reason I am having trouble doing it with JavaScript. 对于我的小应用程序,我需要做一些非常简单的数学运算……但是由于某种原因,我在使用JavaScript时遇到了麻烦。

Here is the code: 这是代码:

(elLeftY <= elementLeftY <= elRightY)

If one of the "questions" is false but the other one is true this little code will always output true... What I want is that only when the two "questions" are true then it equals true but if one of the two is false then it equals false. 如果“问题”之一为假,但另一个为“ true”,则此小代码将始终输出“ true”……我想要的是,只有当两个“问题”为“ true”时,它才等于“ true”,但是如果两个“ questions”为“ true”假,则等于假。

Thanks allot in advance. 预先感谢分配。

You can't do it like that in javascript. 您无法在javascript中做到这一点。 You need this instead: 您需要此:

(elLeftY <= elementLeftY) && (elementLeftY <= elRightY)

Here is how your current code is being evaluated: 这是您当前代码的评估方式:

(elLeftY <= elementLeftY <= elRightY)
((elLeftY <= elementLeftY) <= elRightY)
(true <= elRightY)
(1 <= elRightY)
true

您无法在Javascript中级联相等检查,您必须将它们分成两个表达式。

((elLeftY <= elementLeftY) && (elementLeftY <= elRightY))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM