如何从 jQuery UI datepicker 获取 dateFormat? [英] How to get the dateFormat from jQuery UI datepicker?

查看:18
本文介绍了如何从 jQuery UI datepicker 获取 dateFormat?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的页面中,datepicker dateFormat 选项是通过根据当前用户的语言设置加载本地化的 .js 文件来自动设置的.在页面的其他地方,我需要格式化一些日期,所以我想从 datePicker 中取回 dateFormat 选项.

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 对象,而不是预期的字符串值.这是一个错误吗?还有其他方法可以检索 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,但是将它从 datepicker 中拉出来会很干净和优雅.

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日期选择器演示站点上,输入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屋!

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