Google Chrome 中的日期选择器 UI 格式错误 [英] Datepicker UI format error in Google Chrome

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

问题描述

我在使用 Jquery UI datepicker 时进行了一些测试,发现日期格式在 Chrome 中无法正常工作 - 如果我输入 13/10/2009,则会出现错误,指出格式不正确.我认为发生的情况是,所有浏览器和验证的格式都是 dd/mm/yyyy,但出于某种原因,chrome 默认为 mm/dd/yyyy - 即它在所有其他浏览器上都可以正常工作,但在谷歌浏览器上不能正常工作.

I have been doing some testing whilst using Jquery UI datepicker and have found that the date format doesn't work correctly with Chrome - if I type 13/10/2009 an error appears saying that it is incorrect format. What I think has happened is that the format is dd/mm/yyyy for all browsers and validation but for some reason chrome has defaulted to mm/dd/yyyy - i.e. it works fine across all other browsers but not Google Chrome.

这是一个链接:https://www.carcreditassured.co.uk/apply-now-poor-rating/(在这种情况下,我会将问题类型更改为三个选择框以提高可用性,但我想知道答案以供将来参考)

Here's a link: https://www.carcreditassured.co.uk/apply-now-poor-rating/ (on this occassion I'm going to change the question type to three select boxes to aid usability but I would like to know an answer for future reference)

这是我的 jquery 代码:

Here's my jquery code:

    $('.date-pick').datepicker({
showOn: 'both',
buttonText: 'Choose a date',
buttonImage: '/images/calendar.png',
buttonImageOnly: true,
dateFormat: 'dd/mm/yy',
numberOfMonths: 1,
showButtonPanel: true
    });

任何建议将不胜感激.最好的祝愿雷切尔

Any advice would be greatly appreciated. Best wishes Rachel

附言在阅读了本论坛上的另一篇文章后,我尝试对 MM 进行大写,这给出了(2009 年 10 月 13 日)的格式,这不是我想要的.

P.S. After reading another post on this forum I tried to captialise the MM and that gives a format of (13 October 2009) which isn't what i'm looking for.

推荐答案

我认为它会查看浏览器的Locale 设置(对于 google,请转到 chrome://settings/language)

I think it looks at the browser's Locale settings (for google, go to chrome://settings/language)

您需要像这样为选择器控件设置它:

You'll need to set it for your picker control like so:

$('.date-pick').datepicker("option", $.datepicker.regional["en-GB"]);

话虽如此,即使我将 Google Chrome 设置为使用美式英语,您的选择器也会为我生成 dd/mm/yyyy 格式的日期,尽管一周从星期日开始,因此它仍然会受到影响,除非您按照以下方式设置控件的文化我提供的代码.

having said that, your picker results in dates in dd/mm/yyyy format for me even if I set Google Chrome to use American English, albeit the week starts with Sunday, so it's still influenced unless you set control's culture as per code I've provided.

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

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