[英]How do you compare a value from jQuery with a fixed number?
How do you compare a value from jQuery with a fixed number? 您如何将jQuery中的值与固定数字进行比较?
I thought this might work but it doesn't: 我认为这可能有效,但无效:
if (parseInt($("#days").value) > 7) {
alert("more than one week");
}
As well as @redsquare 's answer to use .val()
, you should specify the radix : 以及@redsquare使用.val()
的答案 ,您还应指定基数 :
if (parseInt($("#days").val(), 10) > 7) {
alert("more than one week");
}
This is because the value could have a leading 0, in which case parseInt
would interpret the value as octal. 这是因为该值的前导0,在这种情况下parseInt
会将值解释为八进制。
if #days is an input then you need .val() instead of value 如果#days是输入,则需要.val()而不是value
eg 例如
if (parseInt($("#days").val()) > 7) {
alert("more than one week");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.