if value is between two numbers

前端 未结 5 2061
无人共我
无人共我 2020-12-18 23:39

I want to be able to test whether a value is within a number range. This is my jQuery code...

if ((year < 2099) && (year > 1990)){
    return \         


        
5条回答
  •  [愿得一人]
    2020-12-19 00:21

    The fast and simple way to make this is to create a function like this:

    function inRange(n, nStart, nEnd)
    {
        if(n>=nStart && n<=nEnd) return true;
        else return false;
    }
    

    Then use that as follows:

    inRange(500, 200, 1000) => this return true;
    

    Or like this:

    inRange(199, 200, 1000) => this return false;
    

提交回复
热议问题