jQuery的日期选择器的Chrome [英] Jquery Datepicker Chrome

查看:201
本文介绍了jQuery的日期选择器的Chrome的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用jQuery UI的日期选择器,我们encouter谷歌浏览器使用时出现问题:
当我们进入一个日期用了一天高于12,它不接受它作为一个有效的日期,这是因为铬认为的日期格式为MM / DD / YYYY。我们试图通过增加code来解决这个试图迫使日期设置为DD / MM / YYYY

When using jQuery UI Datepicker, we encouter a problem when used in Google Chrome: when we enter a date with a day higher than 12, it does not accept it as a valid date, this is because chrome thinks the dateformat is mm/dd/yyyy. We tried to solve this by adding code to try to force the date settings into dd/mm/yyyy

$('.date').datepicker({ dateFormat: "dd/mm/yy" });

有没有办法解决这个问题,所以我们的日期选择器会接受DD / MM / YYYY值?
我们只有这个问题在谷歌Chrome,该datefix适用于火狐,即&安培;苹果浏览器。
我们使用ASPX&安培; MVC3这个项目。

Is there any way to resolve this issue, so our datepicker will accept dd/mm/yyyy values? We only have this issue in google Chrome, the datefix works for firefox, ie & safari. We are using ASPX & MVC3 with this project.

如果有人能解决我们的问题,这将是巨大的。

If someone could solve our issue, that would be great

感谢

推荐答案

我也有同样的问题,并与所有基于Webkit的网络浏览器有关。如果设置大写字母M文本框中显示字母蛀虫。对我来说,最好的解决办法是覆盖从jquery.validate.js的验证日期函数

I have had the same problem and is related with all Webkit based web browsers. If you set uppercase M the textbox show the moth with letters. The best solution for me was to override the validate date function from jquery.validate.js

创建jquery.validate.date.js并确保其jquery.validate.js后装入

Create jquery.validate.date.js and ensure it is loaded after jquery.validate.js

添加以下code到jquery.validate.date.js

Add the following code to jquery.validate.date.js

$(function() {
    $.validator.methods.date = function (value, element) {
        if ($.browser.webkit) {

            //ES - Chrome does not use the locale when new Date objects instantiated:
            var d = new Date();

            return this.optional(element) || !/Invalid|NaN/.test(new Date(d.toLocaleDateString(value)));
        }
        else {

            return this.optional(element) || !/Invalid|NaN/.test(new Date(value));
        }
    };
});

这篇关于jQuery的日期选择器的Chrome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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