如何从jQuery UI datepicker获取dateFormat? [英] How to get the dateFormat from jQuery UI datepicker?
问题描述
在我的页面中,通过根据当前用户的语言设置加载本地化的.js文件,可以自动设置datepicker dateFormat选项。在页面的其他地方,我需要格式化一些日期,所以我想将dateFormat选项从datePicker中退出。
In my page, the datepicker dateFormat option is being set automatically by loading a localized .js file according to the current users's language settings. Elsewhere in the page, I need to format some dates, so I'd like to get the dateFormat option back out of the datePicker.
jQuery文档说可以如下检索dateFormat选项:
The jQuery documentation says you can retrieve the dateFormat option like so:
$('.selector').datepicker('option', 'dateFormat');
但是,这将返回一个包装datePicker的jQuery对象,而不是预期的字符串值。这是一个bug吗?有没有另外一种方法来检索dateValue选项?
However, this returns a jQuery object wrapping the datePicker, not a string value as expected. Is this a bug? Is there another way to retrieve the dateValue option?
我正在使用jQuery 1.3.2和jQuery UI 1.7.1。
I'm using jQuery 1.3.2 and jQuery UI 1.7.1.
我知道我可以简单地查看dateFormat的另一种方式,但将它从日期戳中拉出将是干净和优雅。
I know that I could simply look up the dateFormat another way, but pulling it out of the datepicker would be clean and elegant.
推荐答案
使用该方法适用于我 1 。有多个项目与选择器类?你知道元素已经被添加为日期选择器吗?
Using that method works for me1. Are there multiple items with the selector class? Do you know that the element has already been added as a date picker?
1 On 日期选择器演示网站,键入
javascript:alert($(#datepicker)。 datepicker('option','dateFormat'));
到地址栏,它会给你mm / dd / yy。
1 On the Date Picker demo site, type
javascript:alert($("#datepicker").datepicker('option', 'dateFormat'));
into the address bar, and it will give you "mm/dd/yy."
这篇关于如何从jQuery UI datepicker获取dateFormat?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!