简体   繁体   English

通过jQuery检查jquery unobtrusive验证是否正确

[英]Check jquery unobtrusive validation is true by jQuery

I use MVC 3 Model Validation Attributes and jquery unobtrusive to show validation error message also use the script when form submitted return a confirm. 我使用MVC 3模型验证属性和jquery unobtrusive来显示验证错误消息也在表单提交时使用脚本返回确认。 So I need to check if the all fields are valid then return Confirm: some thing like the following pseudo-script: 所以我需要检查所有字段是否有效然后返回确认:有些事情如下面的伪脚本:

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

But I don't know what exactly should be in the if condition. 但我不知道if条件到底应该是什么。 What is your suggestion? 你的建议是什么?

if ($(this).valid()) {

    var Message = $('#FormConfirmMessage').val();
    return confirm(Message);
}

if ($(this).validate() = true) // your if condition should be "==". change to like this 变成这样的

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM