日期:2014-05-17  浏览次数:20948 次

如何比较输入框输入数值的大小
有2个输入框a1和a2在提交的时候我要比较他的大小,好象直接用request.form(a1)和request.form(a2)不能直接比较,我输入的时候已经控制输入只能为数值了啊

------解决方案--------------------
递交前:
var a1 = document.form_name.a1.value;
var a2 = document.form_name.a2.value;
if(a1> a2){
...
}

递交后:
a1 = request.form( "a1 ")
a2 = request.form( "a2 ")
If a1> a2 Then
...
------解决方案--------------------
用JS就可以实现
<script language= "javascript ">
function check1()
{
if(parseInt(document.all[ "T1 "].value)> parseInt(document.all[ "T2 "].value))
{
alert ( 'T1比T2大 ');
}
else
{
alert ( 'T2比T1大 ');
}
}
</script>
<form method= "POST " action= "test.asp " name= "form1 ">
<input type= "text " name= "T1 " size= "20 ">
<input type= "text " name= "T2 " size= "20 ">
<input type= "button " name= "button " value= "我检查 " onclick= "javascript:check1(); ">
</form>
------解决方案--------------------

递交前:
parseInt(a1)> parseInt(a2)
递交后:
cint(a1)> cint(a2)
------解决方案--------------------
如楼上
类型强制转换后再比较即可。