Chrome中不显眼的验证将无法以dd / mm / yyyy验证 [英] Unobtrusive validation in Chrome won't validate with dd/mm/yyyy

查看:178
本文介绍了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 / mm / yy'。

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/8/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>


推荐答案

四小时后,我终于偶然发现了 answer 。由于某些原因,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天全站免登陆