jQuery验证插件错误:TypeError:验证器未定义 [英] jQuery validation plugin error: TypeError: validator is undefined

查看:116
本文介绍了jQuery验证插件错误:TypeError:验证器未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是该表单的html代码:

Here is html code for the form:

<form method="post" id="login" action="/login">
 <div class="login-element">
    <label for="email">E-Mail</label>
    <input type="text" name="email">
</div>
<div class="login-element">
    <label for="password">Passwort</label>
    <input type="password"  name="password">
</div>
<div class="login-element">
    <input type="submit" value="Login">
</div>
</form>

这是我用于验证的代码:

and here is the code that I used for validation:

    $(document).ready(function() { 
    $("#login").validate({
       debug: true,
       rules: {
            email: {
              required: true,
              email: true
            },
            password: {
              required: true
            }
        },
        messages: {
            email: {
                required: "Please enter a email adress",
                email: "Please enter a valid email address"
            },
            password:"Please enter password"
        }
    });
    });

在控制台中,记录以下错误:

In the console following error is logged:

TypeError: validator is undefined
...or.settings[eventType] && validator.settings[eventType].call(validator, this[0],...

这里可能是什么问题?

推荐答案

发生此错误是因为我有另一个具有相同ID的html元素. 删除该ID代码后,效果很好.

This error happened because I had another html element with same id. After removing that id code worked fine.

这篇关于jQuery验证插件错误:TypeError:验证器未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆