如何检查数字是否介于两个值之间?

编程入门 行业动态 更新时间:2024-10-28 14:26:38
本文介绍了如何检查数字是否介于两个值之间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在JavaScript中,如果窗口大小超过500px,我告诉浏览器执行某些操作。我是这样做的:

In JavaScript, I'm telling the browser to do something if the window size is greater than 500px. I do it like so:

if (windowsize > 500) { // do this }

这很好用,但我想应用同样的方法,但是有一系列的数字。所以如果窗口大小介于500和600px之间,我想告诉我的浏览器。我知道这不会起作用,但这就是我想象的方式。

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 500 and 600px. I know this wouldn't work, but here is how I Imagined it.

if (windowsize > 500-600) { // do this }

这在JavaScript中是否可行?

Is this even possible within JavaScript?

推荐答案

测试 windowsize 是否大于 500 且小于 600 意味着值 500 或 600 本身将导致条件成立。

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.

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

更多推荐

如何检查数字是否介于两个值之间?

本文发布于:2023-10-30 12:27:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1542840.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两个   数字

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!