js获取表单数据

找错
=================================
function qbg(){
var hf=document.getElementById("id1").value;
var ye=document.getElementById("id2").value;
if(hf>ye){
alert("钱不够");
return false;

}
}
======================================================
<body><form action="23.html">
<input type="hidden" id="id1" value="100" />
<input type="hidden" id="id1" value="50" />
<input type="submit" value="提交" onclick="return qbg()" />
==========================================================
为什么根本就没有做比较 直接提交到23.html??望高手解答 跪求

因为用的提交按钮是submit,没有进行提交验证。你得把<form>中加一句onsubmit="return(qbg())"去掉submit的onclick事件..这样就不会自动提交,而会在提交前调用qbg()函数的返回值。。。不过如果是数据比较最好转换成数字。。
var hf=parseInt(document.getElementById("id1").value);
var ye=parseInt(document.getElementById("id2").value);
这样就行了。。。
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答