-
-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
blur事件触发验证 #8
Comments
有空帮你看看, @itlily 为什么用点击呢? |
现在很多表单的场景是 blur就触发条件判断显示信息的。所以想请教一下有没有相关的实现思路。看来只能在blur事件中再单独处理了,感谢. |
给你一个思路,onblur 事件调用 将返回的地方生成到,对应的错误节点上去, 来了个例子你运行一下看看 <form name="example_form" action="#" method="POST" class="form-horizontal">
<div class="form-group">
<label for="req">必填字段:</label>
<input type="text" name="req" class="form-control" placeholder="必填" onblur="blurValidate(this)">
<div id="req"></div>
</div>
<button class="btn-default" type="submit" name="submit">提交按钮</button>
</form>
<script type="text/javascript">
var validator = new Validator('example_form',[
{
name:"req",
display:"必填字段不能为空",
rules: 'required'
},{
name:"alphanumeric",
display:"字数小于5个字符|大于15个字符",
rules: 'min_length(5)|max_length(15)'
},{
name:"email",
display:"请输入您的{{email}}|这不是一个邮箱",
rules: 'required|is_email'
},{
name:"minlength",
display:"不能为空|至少输入8个字符,您输入的{{minlength}}长度少于8",
rules: 'required|min_length(8)'
},{
name:"tos_checkbox",
display:"复选框不能为空",
rules: 'required'
}
])
function blurValidate(e){
var val = validator.validate();
for(var i=0;i< val.errors.length;i++){
if(e.name == val.errors[i].name){
document.getElementById(e.name).innerHTML = val.errors[i].display
}
}
}
</script> 可能说得不太清楚,但是希望你能懂 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
我的办法是:使用onblur触发验证。
问题是:会显示所有的验证没通过的信息。可以只显示当前的吗?
The text was updated successfully, but these errors were encountered: