检查输入值是否为300或以上 [英] Check if input value is 300 or above
本文介绍了检查输入值是否为300或以上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种方法可以使用jQuery检查值是否大于300?我已经在下面创建了脚本,但是我不知道如何检查该值是否大于300.
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>
提前谢谢!
推荐答案
将值解析为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();
}
});
});
这篇关于检查输入值是否为300或以上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文