检查 jquery 不显眼的验证是否为 true by jQuery

Check jquery unobtrusive validation is true by jQuery

本文关键字:true by jQuery 是否 验证 jquery 不显眼 检查      更新时间:2023-09-26

我使用 MVC 3 模型验证属性和 jquery 不显眼地显示验证错误消息,当提交的表单返回确认时,也使用该脚本。所以我需要检查所有字段是否有效,然后返回确认:类似于以下伪脚本的东西:

$('div.FormNeedConfirm form').submit(function () {
    if ($(this).validate() == true) {
        var Message = $('#FormConfirmMessage').val();
        return confirm(Message);
    }
});

但我不知道在 if 条件下到底应该是什么。你有什么建议?

if ($(this).valid()) {
    var Message = $('#FormConfirmMessage').val();
    return confirm(Message);
}

if ($(this).validate() = true) // your if condition should be "==".改成这样

if ($(this).validate() == true)