检查数字是否在范围内 [英] Check if number is in range
本文介绍了检查数字是否在范围内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在检查来自输入字段的号码是否在范围内
I am checking if my number coming from a input field is in range
function timeCheck(){
var time = $.trim($('#enterTime').value());
Number.prototype.between = function(min,max){
return this > min && this < max;
};
if ((time).between(1,9)){
alert("test");
}
}
但不知何故它不起作用..警报是永远不会被触发
But somehow it does not work .. the alert is never triggered
感谢您的帮助和快速回答
Thanks for help and fast answer
推荐答案
扩展@ Daniel的回答是,还有另外两个错误:第一, $('#enterTime')。value()
不是一个有效的jQuery函数,应该是 $( '#enterTime')。VAL()
。其次,您需要将值转换为数字
。否则,您将尝试访问字符串的属性之间的,该属性不存在。最终的代码是:
Extending @Daniel's answer, there are two other errors: first, $('#enterTime').value()
is not a valid jQuery function, should be $('#enterTime').val()
. Second, you need to convert your value to type Number
. Otherwise, you will be trying to access the between
property of a string, which doesn't exist. The final code would be:
function timeCheck(){
var time = new Number($.trim($('#enterTime').val()));
Number.prototype.between = function(min,max){
return this > min && this < max;
};
if(time.between(1,9)){
alert("test");
}
}
这篇关于检查数字是否在范围内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文