Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
219 views
in Technique[技术] by (71.8m points)

javascript - 如何检查数字是否在两个值之间?(How to check if a number is between two values?)

In JavaScript, I'm telling the browser to do something if the window size is greater than 500px.(在JavaScript中,如果窗口大小大于500px,我要告诉浏览器执行某些操作。)

I do it like so:(我这样做是这样的:)
if (windowsize > 500) {
    // do this
}

This works great, but I would like to apply this same method, but with a range of numbers.(这很好用,但是我想使用相同的方法,但是要有一定范围的数字。)

So I would like to tell my browser to do stuff if the window size is between 500px and 600px.(所以我想告诉我的浏览器在窗口大小介于500px和600px之间时做些什么。) I know this wouldn't work, but here is how I imagined it:(我知道这行不通,但是这是我的想象:)
if (windowsize > 500-600) {
    // do this
}

Is this even possible, within JavaScript?(在JavaScript中甚至可能吗?)

  ask by Dyck translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Tests whether windowsize is greater than 500 and lesser than 600 meaning that neither values 500 or 600 itself will result in the condition becoming true.(测试windowsize是否大于500且小于600这意味着值500600本身都不会导致条件变为真。)

if (windowsize > 500 && windowsize < 600) {
  // ...
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...