我想从浏览器语言设置 Jquery UI DatePicker 日期格式,例如,如果 Google Chrome 中的“英语(英国)”在语言和输入设置...中位于顶部(chrome://settings/languages) 那么日期格式应该是 dd/mm/yyyy 如果“English (United States)”在列表的顶部那么日期格式应该是 mm/dd/yyyy。有什么方法可以在 Chrome、Firefox 和 IE 中从浏览器语言设置日期格式...?
最佳答案
在你的情况下,我建议检查语言
var userLang = navigator.language || navigator.userLanguage;
// detect browser language but not a decent one
if (userLang === "en-US") {
$( ".selector" ).datepicker( "option", "dateFormat", "mm/dd/yyyy" );
} else {
$( ".selector" ).datepicker( "option", "dateFormat", "dd/mm/yyyy" );
}
更新:
我正在研究 jQuery 日期选择器的本地化,这里是 nice discussion以及一个不错的插件。
jQuery-localization , 它检测语言并为其加载相应的区域语言
$.localise('js/jquery.ui.datepicker');
Note: By default, it looks at the locale set for the browser and requests localisations of the specified package based on that. For example, if the locale is Portuguese/Brazil (pt-BR), it will load js/jquery.ui.datepicker-pt.js and js/jquery.ui.datepicker-pt-BR.js.
关于javascript - 如何根据浏览器语言设置 Jquery UI Datepicker 日期格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23153542/