日期:2014-05-17  浏览次数:20981 次

客户端数据验证
想实现客户端的数据验证:
<script   language= "javascript ">
function   check()    
{
      ......
      ......
}
//该函数是验证函数
//当验证到错误(如必填项未填)时,返回false,否则返回true
</script>
现有一个提交按钮submit,如何才能实现数据验证功能?
<input   type= "submit "   name= "submit "   onclick= "check() "> 吗?


------解决方案--------------------
<input name= "Submit " type= "submit " class= "form04 " value= "注 册 " onclick= "return check(); " />

<script language= "javascript ">
function check()
{
var UserName = document.form1.UserName.value;

if (UserName== " ")
{
alert( "请输入用户名! ");
document.form1.UserName.focus();
return false;
}

}
</script>
------解决方案--------------------
To :longlangaa() 实在是对不起,我看错了,我以为是text文本框了

请把把那个onblur改为onclick,如果是输入框可以用onblur这个


同时,你的check()函数返回值应该是true 或者false,这样才行,在一个看一下是不是你的check里面有错误,没有走到return 语句阿,如果是这样的话,那么就会提交了

<input type= "submit " name= "submit " onclick= "return check() ">
------解决方案--------------------
function checkinfo()
{
if(FormInfo.email_user.value== " "||
FormInfo.PassportID.value== " "||
FormInfo.Age.value== " "||
FormInfo.QQ.value== " "||
FormInfo.TaobaoID.value== " "||
FormInfo.HopeCity.value== " "||
FormInfo.HaveWebsite.value== "http:// ")
{
alert( "请填写必填项! ");
return false;
}
else return true;

}
这样吧?
------解决方案--------------------
想实现客户端的数据验证:
<script language= "javascript ">
function check()
{
if(document.form1.test.value== " "){
alert( "error ");
return false;
}else{
document.form1.submit();
}
}
//该函数是验证函数
//当验证到错误(如必填项未填)时,返回false,否则返回true
</script>
现有一个提交按钮submit,如何才能实现数据验证功能?
<form id= "form1 " name= "form1 " method= "post " action= " ">
<input type= "text " name= "test " />
<input type= "submit " name= "submit " onclick= "check();return false; "> 吗?
</form>

------解决方案--------------------
to 楼上:

向下面那样写就行了

<script language= "javascript ">
function check()
{
if(document.form1.test.value== " "){
alert( "error ");
return false;
}else{
return true;
}
}
//该函数是验证函数
//当验证到错误(如必填项未填)时,返回false,否则返回true
</script>
现有一个提交按钮submit,如何才能实现数据验证功能?
<form id= "form1 " name= "form1 " method= "post " action= " ">
<input type= "text " name= "test " />
<input type= "submit " name= "submit " onclick= "return check(); ">
</form>


------解决方案--------------------