Javascript “x 是否大于 y 且小于 z”的表达式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8236847/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Expression for "is x greater than y and less than z"?
提问by veryserious
I'm trying to test if a number is greater than 0 but less than 8. How do I do that in JavaScript?
我正在尝试测试一个数字是否大于 0 但小于 8。我如何在 JavaScript 中做到这一点?
This is what I'm trying:
这就是我正在尝试的:
if (score > 0 < 8) { alert(score); }
回答by Joseph Silber
Here's the code:
这是代码:
if (score > 0 && score < 8){
alert(score);
}
P.S. This has nothing to do with jQuery. It's simple, nakedJavaScript!
PS 这与 jQuery 无关。这很简单,赤裸裸的JavaScript!
回答by Dave Newton
if ((score > 0) && (score < 8)) {
alert(score);
}
But this is JavaScript, not jQuery.
但这是 JavaScript,而不是 jQuery。
回答by Alex Peattie
Try:
尝试:
if(score > 0 && score < 8){alert(score);)