【问题标题】:How to make jQuery validation plugin work for drop-down in IE如何使 jQuery 验证插件适用于 IE 中的下拉菜单
【发布时间】:2013-05-18 00:13:38
【问题描述】:

http://bassistance.de/jquery-plugins/jquery-plugin-validation/ 的 jQuery 验证插件在 IE 中存在下拉问题。我正在使用 jQuery 1.7.2、验证插件 1.9.0 和 jQuery UI 1.8.21。

请看:http://quickshare.spreadsheet-converter.com/l/p/4jp8gq42fv57/

  • 在 IE 7 中,验证有效,即它阻止表单提交,但不应用“错误”类。虽然处于无效状态后,我可以选择有效值。 (虽然我的 IE 7 不是我关心的问题。)

  • 在 IE 8 中,验证有效,应用了“错误”类,所以我看到周围有“红色”边框。但是,在处于无效状态后,我无法打开下拉菜单 - 它会自动折叠。不过,我可以双击选择有效值。

  • 在 IE 9 中,验证有效,应用了“错误”类,但在处于无效状态后我无法选择有效值。下拉菜单通过单击和双击自动打开和关闭。我也无法使用左/右键更改值 - 这通常可以通过下拉菜单实现。

有什么提示吗?

谢谢!

更新:演示页面http://jquery.bassistance.de/validate/demo/radio-checkbox-select-demo.html 适用于下拉菜单,并且“错误”类也适用于无效状态。会不会和CSS有关?

更新 2:我在一个普通页面中测试了 1.9 和新版本 1.10 的验证插件。我发现像这样初始化 errorPlacement 对象会导致问题。即使我评论 errorPlacement 的主体功能,问题也会消失。插件网站的demo不是这样的。

$('#formc').validate({      
    errorPlacement: function(error, element){               
        //$(element).attr({'title': error.text()});
    }

【问题讨论】:

    标签: jquery jquery-validate


    【解决方案1】:

    看起来 IE 不喜欢选择的标题属性。就我而言,我在 errorPlacement 中使用引导工具提示。我的修复看起来像这样:

    errorPlacement: function (error, element) {
                    $(element).tooltip({ title: $(error).text(), container: 'body' });
            }
    

    这完全忽略了设置标题属性。您还可以确定该元素是否是一个选择并尝试一些替代选项,如下所示:

    errorPlacement: function (error, element) {
                    if($(element).is('select'){
                     ...do something else
                    }
                    else{
                        $(element).attr({'title': error.text()});
                    }
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-21
      • 1970-01-01
      • 1970-01-01
      • 2015-05-04
      • 1970-01-01
      • 2019-02-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多