0
我想验证我的表单中的两个字段。 但它只显示一个字段的错误信息。 以下是Javascript代码:验证多个空字段
function req() {
if (document.reg_indi_form.txt_fnm.value=="") {
document.getElementById('i').innerHTML="*This field is required";
document.getElementById('i').style.color="red";
return false;
}
if (document.reg_indi_form.txt_lnm.value=="") {
document.getElementById('i1').innerHTML="*This field is required";
document.getElementById('i1').style.color="red";
return false;
}
}
HTML代码:
<input name="txt_fnm" type="text" id="txt_fnm"/> <label id="i"></label>
<input name="txt_lnm" type="text" id="txt_lnm"/>\<label id="i1"></label>
把你的'return'声明在结尾,而不是Ø f在每个if语句之后 – bruchowski 2014-10-11 08:40:28