开发者

How to use jQueryValidation without using name attributes

开发者 https://www.devze.com 2023-02-25 18:29 出处:网络
I\'m using jQueryValidation and I would like to validate my form without needing to use name attributes.

I'm using jQueryValidation and I would like to validate my form without needing to use name attributes.

If the form elements don't have the name attribute on开发者_开发知识库ly the first element is validated.

<!DOCTYPE html>
<html>
    <head>
        <title>jQuery Validation Demo</title>
        <script src="jquery.js" type="text/javascript"></script>
        <script src="jquery.validate.min.js" type="text/javascript"></script>
        <script type="text/javascript">
        $(document).ready(function() {
            $('#loginButton').click(function(){
                $('form').validate();
            });
        });
        </script>
    </head>
    <body>
        <form action="#" id="loginForm">
            <input type="text" id="userText" class="required" placeholder="User" />
            <input type="password" id="passwordText" class="required" placeholder="Password" />
            <input type="submit" id="loginButton" value="Login" />
        </form>
    </body>
</html>

Thanks.


Try like this.

   $("#loginForm").validate({

                rules: {
                      userText:"required"
                       }
                     });


You have to use name attribute in order to use class="required"

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号