1

作者: 风过留香_3356 | 来源:发表于2018-06-13 13:50 被阅读0次
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <script src="jquery-1.9.1.min.js"></script>
        <script src="jquery.validate.min.js"></script>
        <script src="messages_zh.min.js"></script>
        <script src="jquery.form.js"></script>
        <style>
            .error{
                color:red;
            }
        </style>
    </head>
    <body>
        <form action="index.php" id="myform">
            <p>
                <input type="text" name="userName">
            </p>
            <p>
                <input type="text" name="age">
            </p>
            <input type="submit">
        </form>
    </body>
    <script>
    var a="请确保以字母开头"
    $.validator.addMethod("letterfirst",function(value,el){
        value=value.toLowerCase();
        var patt=/^[a-z]/;
        return this.optional(el)||patt.test(value);
    },a)
        $("#myform").validate({
            rules:{
                userName:{
                    required:true,
                    letterfirst:true,
                    remote:{
                        url:"index.php"
                    }
                },
                age:"required"
            },
            messages:{
                userName:{
                    remote:"用户名已存在"
                }
            },
            errorPlacement:function(error,el){
                el.css({border:"2px solid red"})
                error.appendTo(el.parent());
            },
            success:function(error){
                error.siblings('input').css({borderColor:"green"});
                error.remove();
            },
            submitHandler:function(form){
                // form.submit();
                $(form).ajaxSubmit({
                    success:function(res){
                        alert(res,"aaaaaaaaaaaaaaaaaaaa")
                    }
                })
            },
            debug:true
        })
    </script>
    </html>
    

    相关文章

      网友评论

          本文标题:1

          本文链接:https://www.haomeiwen.com/subject/fbareftx.html