如何使用户在输入数据时,自动验证格式是否正确?不要返回服务器端,在客户端完成?
就像QQ号码申请那样,如果输错自动有验证框跳出?
------解决方案-------------------- <script>
function check(form){
if(form.shuru.value== " "){
alert( "输入不能为空! ");
return false;
}else{
alert( "提交成功! ");
}
}
</script>
<form onsubmit= "return check(this) ">
<input type= "text " name= "shuru " /> 不能为空 <br />
<input type= "submit " value= "提交 " />
</form>
------解决方案--------------------一般客户端进行的是格式或者是否为空的验证
如果验证密码还需要服务器端的
客户端可以缩短验证时间
你可以参考我佛山人的表单验证类
演示:
http://wishwing.net/validator.htm
下载:
http://wishwing.net/validator.rar
相关讨论:
http://bbs.blueidea.com/viewthread.php?tid=1834871
------解决方案-------------------- <script>
function check(obj){
var form=obj.form;
var result=document.getElementById( "result ");
if(form.pw1.value!= " "){
if(form.pw1.value!=form.pw2.value){
result.innerHTML= "不一致 ";
}else{
result.innerHTML= "一致 ";
}
}
}
</script>
<form>
<input type= "password " name= "pw1 " onpropertychange= "check(this) " />
<input type= "password " name= "pw2 " onpropertychange= "check(this) " />
<span id= "result "> 请输入密码 </span>
</form>
------解决方案--------------------这样的算不算…………?
<script language= "JavaScript ">
function cbm_Focus()
{
if(document.form1.ML.value== " ")
{
alert( 'CTN Size Long Cannot be spatial ');
return false;
}
</script>
<form id= "form1 " name= "form1 " action= " " method= "post ">
<input name= "ML " type= "text " id= "ML " size= "5 " maxlength= "5 " />
<input name= "cbm " type= "text " id= "cbm " size= "50 " maxlength= "50 " onFocus= "cbm_Focus() " />
</form>