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

Categories

Is there a way to check if the value is above 300 using jQuery? I have made the script below but I have no idea on how to check if the value is above 300.

$(document).ready(function(){
    $("input").on('keyup', function() {
        if( $(this).val() == '300' ) {
             alert("Stop it now! You're above the 300 mark! I told you to stop, you dum dum!");
        }
    });
});
<input type="text">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
See Question&Answers more detail:os

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

1 Answer

Parse the value to int.

    $(document).ready(function(){
        $("input").on('keyup', function() {
            if( Number($(this).val()) > 300 ) {
                 alert("Stop it now! You're above the 300 mark, damn it! I told you to stop, you dum dum!");
            } else {
               //Hide your div here
               $("#ElementID").hide();
            }
        });
    });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...