Jquery how to check if a input has a number higher then 99

后端 未结 8 1182
离开以前
离开以前 2021-01-06 05:08

Was wanting to know how to check using jquery if a input contains a number higher then 99

相关标签:
8条回答
  • 2021-01-06 05:18

    Simply use this:

    if ($("input.INPUTNAME").val() > 99) {
    //above 99 code
    }
    

    You may want to have an else command, if the input is below 99.

    if ($("input.INPUTNAME").val() > 99) {
        //above 99 code.
        }
    else{
         //Not above 99 code.
    }
    
    0 讨论(0)
  • 2021-01-06 05:19
    if(parseInt($(YOURINPUT).val()) > 99) // do something
    
    0 讨论(0)
  • 2021-01-06 05:21

    This would do it

    var value = $("input selector").eq(0).val();
    if(isNaN(value)){
     //do stuff
    }
    
    else{
    var num = value - 0;
    if(num>99)
    {
     //value is greater than 99
    }
    
    }
    
    0 讨论(0)
  • 2021-01-06 05:23

    I guess typically with jQuery you would have to have the name of the form

    <form id="myForm" action="comment.php" method="post"> 
        number: <input id="form_number" type="text" name="number" /> 
        Comment: <textarea name="comment"></textarea> 
        <input type="submit" value="Submit Comment" /> 
    </form>
    

    you would select the form and its input.

    var myInt = parseInt(jQuery("#form-number-url").attr("value"));
    

    then you can compare it with any other integer.

    0 讨论(0)
  • 2021-01-06 05:24

    Use this:

    html:

    <input type="text" id="myInput" />
    

    jquery:

    var nMyInput = $("#myInput").val();
    if (typeof nMyInput != "undefined"){
        if(!isNaN(nMyInput)){
            if (parseInt(nMyInput) > 99) {
                /* do your stuff */
            }
        }
    }
    
    0 讨论(0)
  • 2021-01-06 05:28

    If by input you mean text, then use the following:

    if (parseFloat($("#inputid").val()) > 99) {
       //do something
    }
    
    0 讨论(0)
提交回复
热议问题