jquery.validate插件

8 篇文章 0 订阅

这是一个表单验证的插件,基于jquery. 用法比较简单,具体请参考下文给出的api链接:

http://jqueryvalidation.org/documentation

上面的文档中有这样一段话值得注意一下:

A few things to look out for when playing around with the demo

  • After trying to submit an invalid form, the first invalid element is focused, allowing the user to correct the field. If another invalid field – that wasn't the first one – was focused before submit, that field is focused instead, allowing the user to start at the bottom if he or she prefers.
  • Before a field is marked as invalid, the validation is lazy: Before submitting the form for the first time, the user can tab through fields without getting annoying messages – they won't get bugged before having the chance to actually enter a correct value
  • Once a field is marked invalid, it is eagerly validated: As soon as the user has entered the necessary value, the error message is removed
  • If the user enters something in a non-marked field, and tabs/clicks away from it (blur the field), it is validated – obviously the user had the intention to enter something, but failed to enter the correct value

That behaviour can be irritating when clicking through demos of the validation plugin – it is designed for an unobtrusive user experience, annoying the user as little as possible with unnecessary error messages. So when you try out other demos, try to react like one of your users would, and see if the behaviour is better then. If not, please let me know about any ideas you may have for improvements!

上面这段话告诉我们:

        jquery.validate插件采用了‘懒校验’机制, 即第一次提交表单之前,在所有表单控件上来回切换都不会触发校验,当然也就不会报错。只有当用户第一次点击了提交并且表单中存在错误时,相应的表单控件会被标识并显示错误。 在此之后,会采用‘饥渴校验‘机制,任何一个控件的blur事件都会立即触发该控件的校验。另外,如果校验之后有多个invalidate控件,第一个将被focus, 但若校验前焦点在第二个invalidate的控件上,则第二会被focus.

        作者认为这样做能提供更好的用户体验,也许它第一眼看上去并不那么’智能‘,多站在你的用户的立场上想想,或许你就会赞同这是个不错的主意。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值