Chrome 中的非侵入式验证不会使用 dd/mm/yyyy 进行验证 [英] Unobtrusive validation in Chrome won't validate with dd/mm/yyyy

查看:19
本文介绍了Chrome 中的非侵入式验证不会使用 dd/mm/yyyy 进行验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用在不同浏览器中使用日期选择器的最简单的场景.我怀疑我正在以错误的方式做一些非常简单的事情,但是经过大量搜索后,我仍然没有找到解决方案.下面是一些代表我正在尝试的示例代码.

I'm trying to use the simplest possible scenario using a date picker in different browsers. I suspect I'm doing something very simple the wrong way but after lots of searching around I still haven't found a solution. Below is some sample code that represents what I'm attempting.

如果我使用 Chrome (v12.0.742.122) 并从选择器中选择一个日期,例如 13/08/2011,jQuery 验证逻辑将不允许页面提交,即使我已明确指定格式为 'dd/毫米/年'.

If I use Chrome (v12.0.742.122) and pick a date from the picker like 13/08/2011 the jQuery validation logic will not allow the page to submit even though I've explicitly specified the format as 'dd/mm/yy'.

如果我将格式更改为dd/M/yy"并选择像 13/Aug/2011 这样的日期,它可以在 Chrome 中运行,但不会在 IE (v8.0.7600.16385) 中为我提交.在 FireFox (v3.6.18) 中,两种格式都可以使用.

If I change the format to 'dd/M/yy' and choose a date like 13/Aug/2011 it works in Chrome but then won't submit for me in IE (v8.0.7600.16385). In FireFox (v3.6.18) both formats work.

我需要什么验证脚本才能在 Chrome 中支持dd/mm/yy"的日期格式?

What validation script do I need to be able to support date formats of 'dd/mm/yy' in Chrome?

<html>
 <head>
  <link rel="stylesheet" type="text/css" href="jquery-ui.css" />
  <script type="text/javascript" src="jquery-1.4.4.js"></script>
  <script type="text/javascript" src="jquery.validate.js"></script>
  <script type="text/javascript" src="jquery.validate.unobtrusive.js"></script>
  <script type="text/javascript" src="jquery-ui.js"></script>
  <script type="text/javascript">
      $(document).ready(function () {
    $('.date').datepicker({ dateFormat: 'dd/mm/yy' });
            $.validator.addMethod("dateRule", function(value, element) {
      return true;
    },
    "Error message");
      });
  </script>
 </head>
 <body>
    <form>
        Date: <input type="text" name="myDate" class="date dateRule" />
        <input type="submit" />
    </form>
 </body>
</html>

推荐答案

四个小时后我终于偶然发现了答案.出于某种原因,Chrome 似乎有一些内在的偏好,即使用美国日期格式,而 IE 和 FireFox 能够明智地使用操作系统上的区域设置.

Four hours later I finally stumbled across the answer. For some reason Chrome seems to have some inbuilt predilection to use US date formats where IE and FireFox are able to be sensible and use the regional settings on the OS.

jQuery.validator.methods["date"] = function (value, element) { return true; } 

这篇关于Chrome 中的非侵入式验证不会使用 dd/mm/yyyy 进行验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆