我想验证我的表单,但我坚持验证表单域 persnr。它不会比较字符串。为此,我已经尝试了比较和运算符(或 || )。其他字段的验证没问题。我用错了运营商吗?
function checkForm() {
var strFehler = '';
if (document.forms[0].user.value == "user")
strFehler += "user not ok!\n";
if (document.forms[0].test.value == "")
strFehler += "test not ok!\n";
if (document.forms[0].time.value == "")
strFehler += "time not ok";
if (document.forms[0].cost.value == "")
strFehler += "cost not ok!\n";
if (document.forms[0].persnr.value != "13088") || (document.forms[0].persnr.value != "10286")
strFehler += "persnr false!\n";
if (strFehler.length > 0) {
alert("problems!!: \n\n" + strFehler);
return (false);
}
}
我希望如果值不是 13088 或 10286 但没有消息弹出,验证会显示警报。
这:
if (document.forms[0].persnr.value != "13088") || (document.forms[0].persnr.value != "10286")
需要改成这样:
if ((document.forms[0].persnr.value != "13088") || (document.forms[0].persnr.value != "10286"))
您缺少括号以在if 语句中包含两个条件。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句