Topic: javascript里如何比较数值?

  Print this page

1.javascript里如何比较数值? Copy to clipboard
Posted by: redhobor
Posted on: 2005-03-20 08:50

<script language="javascript" type="">
<!--
//Check the total weight of exams and courseworks
function calculateWeight() {
var weight, weight1, weight2;
weight1=document.frm.rst_exmtotalweight.value;
weight2=document.frm.rst_cwktotalweight.value;
weight=weight1+weight2;
if (weight!=100){
window.alert("The total weight of exams and courseworks is not correct!");
document.getElementById("rst_cwktotalweight").focus();
return false;
}
frm.submit();
}
//-->
</script>
<form name="frm" method="post" action="definemdlstructservlet" onsubmit="return calculateWeight(this);">
<tr bgcolor="#CCCCCC">
<td>How many weight of exams? [100%] </td>
<td width="56%" bgcolor="#FFFFFF">
<input type="text" id="rst_exmtotalweight" name="rst_exmtotalweight" value="0" size="5" style="display:none;">
</td>
</tr>
<tr bgcolor="#CCCCCC">
<td>How many weight of courseworks? [100%] </td>
<td width="56%" bgcolor="#FFFFFF">
<input type="text" id="rst_cwktotalweight" name="rst_cwktotalweight" value="0" size="5" style="display:none;">
</td>
</tr>
</table>
<p> </p>
<p>
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Reset" value="Reset">
<input type="button" name="back" value="Back" onClick="history.back(-1)">
</p>
</form>
为什么我输入数值后,即使相加等于100,仍然会出现错误警告。
如果从数据库得的rst_exmtotalweight和rst_cwktotalweight都是double类型数据,程序需要改进吗?
谢谢!

2.Re:javascript里如何比较数值? [Re: redhobor] Copy to clipboard
Posted by: caozhe2005
Posted on: 2005-04-04 14:32

估计在付值的时候就要强制转换成INTEGER型的


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923