JQuery 1.6 $('form').validate()在IE7和IE8中不起作用

Ste*_* P. 18 jquery jquery-validate asp.net-mvc-3

更新:我用Razor HTML 5创建了一个新的MVC 3项目,然后我在JQuery 1.6上使用NuGet更新了项目,并且验证插件不再起作用,它每次都会回发并返回错误服务器的消息.我认为使用JQuery 1.6打破了验证插件

我有一个MVC 3应用程序,它使用Jquery UI对话框(从包含表单的部分视图加载),以便通过ajax向服务器提交信息.我想在执行ajax发布之前在客户端触发我的表单验证.在Firefox和IE9上运行正常,在IE7和IE8中,form.validate()始终返回true.

这是附加到我的提交按钮的js代码:

    var wizard = $("#wizard"); //div that holds the modal dialog
    var myform = $("#wizard form");

    var submitFunction = function (e) {
        e.preventDefault(); //no postback
        myform.validate();
        if (myform.valid()) {
            $(this).attr("disabled", "disabled");
            submited = true;
            $.post(
                "SuperAdmin/CreateEditController",
                $(this).serialize(),
                function (data) {
                    if (data.Success) {
                        wizard.dialog('destroy');
                    }
                    else {
                        wizard.html(data.Html);
                    }
                },
                "json"
            ); //end json post
        }
    };
myform.submit(submitFunction);
Run Code Online (Sandbox Code Playgroud)

我使用以下包括:

<script src="@Url.Content("~/Scripts/jquery-1.6.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud)

JQuery Validation插件使用版本1.8.0的NuGet和JQuery库升级到1.6.

更新:我已经测试了使用脚手架默认模板生成的代码,它做了同样的事情,没有客户端验证.也许JQuery 1.6与Razor脚手架模板不兼容?

Sic*_*pie 19

Jquery Validate目前不适用于IE6,IE7和IE8中的jQuery 1.6.

https://github.com/jzaefferer/jquery-validation/issues/105

  • 我正在把头发拉出来.获取最新版本的jquery.validate修复了该问题. (7认同)

nul*_*ble 5

我在IE7/IE8中遇到了jquery.validate.js的问题.调试后我注意到以下行引起了问题(版本1.7中的ln 436):

return $([]).add(this.currentForm.elements)
            .filter(":input")
Run Code Online (Sandbox Code Playgroud)

用以下内容替换这两行:

return $(':input', this.currentForm)
Run Code Online (Sandbox Code Playgroud)

这对我有用.