有没有办法可以获得javascript函数返回值里的bool值,代码如下:

来源:百度知道 编辑:UC知道 时间:2024/09/20 23:49:45
function submitClick()
{
if (document.getElementById("userID").value=="")
{
document.getElementById("IsEmptyID").innerHTML = "<font color='red'>* 帐号输入不能为空</font><br />";
}
if (document.getElementById("PW").value=="")
{
document.getElementById("IsEmptyPW").innerHTML = "<font color='red'>* 密码输入不能为空</font><br />";
}
if (document.getElementById("PWQ").value=="")
{
document.getElementById("IsEmptyQuestion").innerHTML = "<font color='red'>* 密码提示问题输入不能为空</font><br />";
}
if (document.getElementById("PWAnswer").value=="")
{
document.getElementById("IsEmptyAns

在每个if里面 写上 return false; 也就是其中任何一项没通过就返回false

在最后面写上 return true; 如果都通过了就会返回真

很简单的,你是用在表单提交时吧

<form action="" onsubmit="submitClick()"> 这样如果返回为假就不会提交了

function submitClick()
{
if (document.getElementById("userID").value=="")
{
document.getElementById("IsEmptyID").innerHTML = "<font color='red'>* 帐号输入不能为空</font><br />";
return false;
}
if (document.getElementById("PW").value=="")
{
document.getElementById("IsEmptyPW").innerHTML = "<font color='red'>* 密码输入不能为空</font><br />";
return false;
}
if (document.getElementById("PWQ").value=="")
{
document.getElementById("IsEmptyQuestion").innerHTML = "<font color='red'>* 密码提示问题输入不能为空</font><br />";
return false