客户端验证
我想实现一个数量和金额之间的关系验证。之前是在服务器端验证的,后来老板说不符合要求,让改成用js验证的,可我对js一窍不通啊,求各位大虾指教,最好有代码啊!公式为:总金额(万元)<=产品数量*7000/10000元,如果不符合要求就给出一个提示!
[解决办法]
<script type ="text/jscript" >
function checkFormat() {
var total = document.getElementById("total").value;
var num = document.getElementById("num").value ;
if (total <= num * 7000 / 10000) {alert("金额不符合要求!");return false;}
}
</script>
<div>
请输入总金额:<input type ="text" id ="total"/><br /><br />
请输入产品数量:<input type ="text" id ="num" /><br />
<asp:Button runat ="server" ID ="btn_OK" Text ="ok" OnClientClick ="return checkFormat();" />
</div>
[解决办法]