单击提交按钮时无法读取未定义的属性“设置”

新手上路,请多包涵

当我将代码更改为 php(来自 html)时,我不知道为什么会收到此错误。当文件的扩展名是 html 时,代码工作正常

 <?php?>
<html lang="en">
<head>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">

        <!-- Latest compiled and minified CSS -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">

        <link rel="stylesheet" href="css/manual.css">
        <!-- Optional theme -->

        <!-- Latest compiled and minified JavaScript -->
        <script src="http://code.jquery.com/jquery-latest.min.js"
        type="text/javascript"></script>


        <!-- Latest compiled and minified JavaScript -->
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>

    <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.14.0/jquery.validate.js"></script>

        <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.14.0/jquery.validate.min.js"></script>
        <title>Register</title>
</head>

<body>

        <nav class="navbar navbar-default" id="navBar">

        </nav>

        <div class="full">
                <div class="col-xs-12">
                        <!--Side Bar-->
                        <div class="col-xs-3" id="navSide">
                        </div>

                        <div class="col-xs-6" id="signUpForm">

                                <h1>Register Page</h1>
                                <form role="form" id="signUpForm">
                                        <div class="form-group">
                                                <div class="form-inline spacer-12">
                                                        <input type="text" class="form-control"  name="userFirstname" placeholder="First Name">
                                                        <input type="text" class="form-control"  name="userLastName" placeholder="Last Name">

                                                </div>
                                        </div>

                                        <div class="form-group ">

                                                <input type="text" class="form-control"
                                                name="userEmail"
                                                placeholder="Email">
                                        </div>

                                        <div class="form-group ">
                                                <input type="password" class="form-control" name="userPassword" placeholder="Password">
                                        </div>

                                        <div class="form-group ">
                                                <input type="password" class="form-control" name="confirmPassword" placeholder="Password">
                                        </div>

                                        <div class="form-group ">
                                                  <label> Birthday* </label>
                                                  <input type="date" class="form-control" name="userBirthday" placeholder="Birthday">

                                        </div>
                                        <input type="submit" class="btn btn-info spacer-12" style="clear:both" >


                                </form>



                        </div>
                </div>
        </div>


        <script src="js/startup.js"></script>
        <script src="js/signup.js"></script>

</body>
</html>

<?php?>

那么这是我的jQuery验证代码

$(document).ready(function(){
    $('#signUpForm').validate({
        errorElement: "span",
        errorClass: "help-block",
        rules:{
            userFirstName:{
                required: true
            },
            userLastName:{
                required: true
            },
            userEmail:{
                required: true
            },
            userPassword:{
                required: true
            },
            confirmPassword:{
                required: true
            },
            userBirthday:{
                required: true
            }
       },
       submitHandler: function (form) { // for demo
           alert('valid form submitted'); // for demo
           return false; // for demo
       },
       highlight: function(element) {

        $(element).closest('.form-group').addClass('has-error').addClass('red-border');
       },
       unhighlight: function(element) {
        $(element).closest('.form-group').removeClass('has-error').addClass('has-success').removeClass('red-border');
       }
   });
});

当我单击提交按钮时,此代码会导致错误(JQuery Validate Uncaught TypeError: Cannot read property ‘settings’ of undefined )但该错误是暂时的,并且会在一段时间内消失。

原文由 Robert Limanto 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 288
2 个回答

您定义了两个具有相同名称的 id,而 id 应该是唯一的。

 <div class="col-xs-6" id="signUpForm">
<form role="form" id="signUpForm">

尝试从 <div class="col-xs-6" id="signUpForm"> 中删除id

原文由 Norlihazmey Ghazali 发布,翻译遵循 CC BY-SA 3.0 许可协议

如果您使用 rules() 方法,请确保首先初始化验证。

 var validator = $("#Form1").validate();
$('#field1').rules("add", {
         min: 1
});

原文由 Michael 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题