2

我是网络开发的新手,在这里我知道问题很小,但即使两天后我也找不到它。你们可以看看这段代码并指出我的错误吗

我的代码 ID在这里@JSFiddle 谢谢

HTML

<form id="registerForm" action="\register" method="post">
    <div class="form-group">
        <input class="form-control" type="text" name="email" placeholder="Email">
    </div>
    <div class="form-group">
        <input class="form-control" type="password" name="pass1" placeholder="Password">
    </div>
    <div class="form-group">
        <input class="form-control" type="password" name="pass2" placeholder="Confirm Password">
    </div>
    <button class="btn btn-primary" type="submit">Signup</button>
</form>

JS

$(document).ready(function () {
    $('.registerForm').bootstrapValidator({
        message: 'This value is not valid',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            email: {
                validators: {
                    notEmpty: {
                        message: 'The email is required and cannot be empty'
                    },
                    emailAddress: {
                        message: 'The input is not a valid email address'
                    }
                }
            },
            pass1: {
                validators: {
                    identical: {
                        field: 'pass2',
                        message: 'The password and its confirm are not the same'
                    }
                }
            },
            pass2: {
                validators: {
                    identical: {
                        field: 'pass1',
                        message: 'The password and its confirm are not the same'
                    }
                }
            }
        }

    });
});
4

3 回答 3

3

要通过 id 获取节点,请使用:$('#registerForm'). 如果你得到了 JS 会在标签中$('.registerForm')寻找类。registerForm<form>

阅读 jQuery API 是防止此类错误的好方法。 http://api.jquery.com/category/selectors/

于 2014-10-17T17:24:05.583 回答
0

您的 JavaScript 绑定到类 registerForm,而不是 id。在 JavaScript 代码中将 .registerForm 更改为 #registerForm。

编辑:或将 class="registerForm" 添加到 html 中的 YouTube 表单元素

于 2014-10-04T07:40:35.347 回答
0

在 Html 表单中分配了一个id="registerForm"和在 js 文件中,您正在调用一个关于类的函数,$('.contactForm')只需更改$('.contactForm')$('#contactForm')希望能解决您的问题。

于 2019-03-31T17:11:44.563 回答