jQuery 验证未在输入有效电子邮件时删除错误

jQuery validation not removing error upon valid email entry

我正在尝试设置 jQuery 验证插件,以便在发送前验证电子邮件地址。我以前做过很多次。

但是对于这个新表单,它无法按预期工作。它不会停止表单提交,并且不会在电子邮件地址有效后删除错误。

我在下面包含了精简代码和 JSFiddle

HTML:

<form action="" id="myform" method="post" name="myform">

    <label for="guest_email">What is your email address?</label>
    <input name="guest_email" placeholder="Email address" type="email"/>

    <button name="guest_submit" type="submit">Confirm</button>

</form>

jQuery:

$(document).ready(function () {

    $("#myform").validate({
        rules: {
            guest_email: {
                require: true,
                email: true
            }
        }
    });

});

我猜这对某些人来说是显而易见的,但我似乎找不到答案。

jQuery.validate.min.js 是从他们的 CDN 调用的。 /1.11.1/jQuery.min.js

我设置表单的方式、我的 JS 和插件之间肯定存在一些冲突。我的方法适用于我网站的不同页面。

好吧,您的代码在 jsfiddle 中运行完美。无论如何,如果它在您的工作站上仍然存在,您可以尝试添加:

$('input[name=guest_email]').change(function ()
{
    $('input[name=guest_email]').valid();
}

已更新

正确的代码

$(document).ready(function(){   
$("#myform").validate({
        rules: {
            guest_email1: {
                required: true,
                email: true
            }
        }
    });
});

Working fiddle :)

最后我得出结论:),你应该写required。你错过了 d