简体   繁体   中英

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. Apparently this should be default behaviour but was broken by the latest version of jQuery.

Now I've tried using

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

And that works for textarea fields. But not for my text input fields. Why is this and how do I get it to work?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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