问答详情
源自:2-1 两个重要概念、validate方法

为什么校验不通过也可以提交

我按照老师说的那么写了之后 但是校验不通过也可以提交数据给后台???那这样怎么行呢

 $("#signup").validate({
        rules:{
            Username:{
                required:true,
                minlength:2
            },
            EmailAddress:{
                required:true,
                email:true
            },
            Password:{
                required:true,
                minlength: 6,
                maxlength: 18
            }
        },
        messages: {
            Username: {
                required:"请输入用户名",
                minlength:"至少两位"
            },
            EmailAddress: {
                required:"请输入密码",
                email:"邮箱格式不对"
            },
            Password:{
                required:true,
                minlength: "最少六位",
                maxlength: "最多18位"
            }
        },
        submitHandler: function (form) { // for demo
            alert('valid form submitted'); // for demo
            $("input[id=submit2]").click(function () {
                event.preventDefault();
                $.post("http://218.192.169.173/taobao/login.php", {
                    email: $("#EmailAddress1").val(),
                    password: $("#PassWord").val()
                }, function (data, textStatus) {
                    var username = data.username;
                    var errnum = data.errno;
                    alert(username);
                },"json");
            });
            return false; // for demo
        }
})
});

这是我的js代码

提问者:深夏之叶 2016-11-18 20:52

个回答

  • 古德里安
    2016-11-18 22:12:25

    会不会是提交按钮(submit2)本身的设置,比如类型就是submit?