简体   繁体   English

jQuery验证onblur textarea与其他输入问题

[英]jQuery validation onblur textarea vs other input issues

I'm having trouble getting the jQuery validation plugin to validate single input elements on blur or lose focus. 我无法让jQuery验证插件在模糊或失去焦点的情况下验证单个输入元素。 Apparently this should be default behaviour but was broken by the latest version of jQuery. 显然,这应该是默认行为,但是被最新版本的jQuery破坏了。

Now I've tried using 现在我尝试使用

onfocusout: function(element){$(element).valid();} onfocusout:function(element){$(element).valid();}

And that works for textarea fields. 这适用于textarea字段。 But not for my text input fields. 但不适用于我的文本输入字段。 Why is this and how do I get it to work? 为什么会这样,如何使它正常工作?

http://jsfiddle.net/zGR5Q/2/ http://jsfiddle.net/zGR5Q/2/

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script type="text/javascript" src="http://jzaefferer.github.com/jquery-validation/jquery.validate.js"></script>

    <script>
        $(document).ready(function(){
            $('#formId').validate({
                    onfocusout: function(element)
                    {
                        $(element).valid();
                    }
            });
        });
    </script>

</head>
<body>

<form id="formId" method="get" action="">

<input id="cname" name="name" size="25" class="required" minlength="2" /><br />
<input id="cemail" name="email" size="25"  class="required email" /><br />
<textarea id="ccomment" name="comment" cols="22"  class="required"></textarea> <br />
<input class="submit" type="submit" value="Submit"/>

</form>
</body>
</html>

you have to write 你必须写

 <input type='text'....

and it works 它有效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM