我知道这可能看起来很愚蠢,但我无法相互检查2个值.以下代码我多次使用它们并且它们可以工作,但在一个实例中它只是做了奇怪的事情.在头版我得到:
<input type=\"text\" name=\"v571\" id=\"v571\" value=\"\" size=\"18\"/>
<input type=\"hidden\" name=\"v571a\" id=\"v571a\" value=\"140\"/>
Run Code Online (Sandbox Code Playgroud)
在js脚本中我有:
if( $('#v571').val() > $('#v571a').val()) {
$('#v571').addClass('error');
error++;
}
Run Code Online (Sandbox Code Playgroud)
这些是结果:
if v571 betweem 100 and 140 -> no error (should get no error)
if v571 less then 100 -> error (should get an error)
if v571 bigger then 140 -> error (should get an error)
if v571 bigger then 140 , but the number starts with 1 (eg: 1000, 1200, 12312, 1xxx...) -> no error (should get an error)
if v571 is 1,10,11 it's ok (should get no error)
if v571 is anything else less then 100 -> error (should get no error)
Run Code Online (Sandbox Code Playgroud)
我也有这个完美的工作:
<input type=\"text\" name=\"v572\" id=\"v572\" value=\"\" size=\"18\"/>
<input type=\"hidden\" name=\"v572a\" id=\"v572a\" value=\"148\"/>
<input type=\"hidden\" name=\"v572b\" id=\"v572b\" value=\"152\"/>
Run Code Online (Sandbox Code Playgroud)
和js:
if( $('#v572').val() < $('#v572a').val() || $('#v572').val() > $('#v572b').val()) {
$('#v572').addClass('error');
error++;
}
Run Code Online (Sandbox Code Playgroud)
使用parseInt比较整数:
var v1 = parseInt($('#v571').val(),10); // always use a radix
var v2 = parseInt($('#v571a').val(),10);
if( v1 > v2) {
$('#v571').addClass('error');
error++;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9043 次 |
| 最近记录: |