jQuery插件验证:重新验证为键入/鼠标焦点 [英] jQuery plugin Validate : revalidate as typing / mouse focus

查看:174
本文介绍了jQuery插件验证:重新验证为键入/鼠标焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于jQuery文档验证演示的表单: http://jsfiddle.net/ABbDS / 1 / 。点击提交或点击回车确认。



如何制作标签 / 更改鼠标焦点 / 打字也验证? (所以他们立即知道这封电子邮件是

它基于: http://jquery.bassistance.de/validate/demo/milk/ (它是这样做的)和 http://docs.jquery.com/Plugins/Validation/



矿井无法验证何时点击下一个元素或点击标签。答案我发现没有使用 validate 插件。



编辑:这是正确答案吗?: https://stackoverflow.com/a/9381803/341744 $(this).valid()调用validate()的函数吗?

http://docs.jquery.com/Plugins/Validation/validate#toptions =nofollow>有关onfocusout和onkeyup的jquery网站上的文档有些误导,它表示onfocusout和onkeyup是布尔值,这会导致您相信您可以将它们的值设置为true或false。错误!你应该只将它们设置为false。如果您将它们的值设置为true,那么您会收到此错误


未捕获TypeError:对象true没有方法'call'


这是因为默认的onfocusout和onkeyup是不是布尔值的函数。如果你设置这个值为false,那么这个函数就不会被调用,但是如果设置为true,那么你会得到一个javascript错误。这种类型的编程对于像我这样的程序员来说很难用来强壮的打字习惯,但是非常聪明。



没有理由将onfocusout设置为true因为默认行为是在失去焦点时进行验证,所以只需在代码中删除这两行即可。

  //删除这些行
// onfocusout:true,
// onkeyup:true


I have a form based on the validation demo of jQuery's docs : http://jsfiddle.net/ABbDS/1/ . Clicking submit or hitting enter does validate it.

How do I make tab / changing mouse focus / typing also validate? ( So they immediately know the email is

It is based off of : http://jquery.bassistance.de/validate/demo/milk/ (which does this) and http://docs.jquery.com/Plugins/Validation/

Mine isn't validating when clicking the next element or hitting tab. Answers I found did not use the validate plugin.

edit: Is this the right answer? : https://stackoverflow.com/a/9381803/341744 Does $(this).valid() call validate()'s function?

解决方案

The documentation on the jquery site concerning onfocusout and onkeyup is slightly misleading. It states that onfocusout and onkeyup are boolean values, which would lead you to believe that you could set their values to true or false. Wrong! You should only set them to false. If you set their values to true then you get this error

Uncaught TypeError: Object true has no method 'call'

This is because the default onfocusout and onkeyup are functions not boolean values. If you set the values to false then the function is not called, but if set to true then boom you get a javascript error. This type of programming is difficult for a programmer like me used to strong typing to get used to, but is pretty clever.

There is no reason to set onfocusout to be true as the default behaviour is to validate on losing focus, so just remove these two lines in your code

// remove these lines
// onfocusout:true,  
// onkeyup: true

这篇关于jQuery插件验证:重新验证为键入/鼠标焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆