jQueryUI datepicker:具有本地化功能的月/年菜单 [英] jQueryUI datepicker: Month/Year Menus with Localization

查看:126
本文介绍了jQueryUI datepicker:具有本地化功能的月/年菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个 jQuery UI datepicker 小部件,该小部件具有月份/年份菜单,如

I'd like to do a jQuery UI datepicker widget that has both month/year menu as seen at datepicker: jQuery UI, but it also needs to be localized, as seen at datepicker jQuery UI:localization.

我不确定两者能否一起完成.我无法使其正常工作.如果添加本地化代码,则可以看到日历正确地本地化,但是丢失了月/年菜单.

I'm not sure if both can be done together. I have not been able to get it to work. If I add the localization code, I do see the calendar localized properly, but I lose the month/year menus.

有关i18n的有效示例,请参见 JsFiddle .如果您将i18n行注释掉:

See JsFiddle for a working sample of the i18n. if you comment out the i18n line:

$( "#dob" ).datepicker( $.datepicker.regional[ "ar" ] );

...然后您会看到月/年菜单正常工作.

... then you'll see the month/year menus work properly.

有人知道有一种方法可以使它们在单个小部件中一起工作吗?

Does anybody know of a way to get these both working together in a single widget?

推荐答案

首先要了解的是,第一次调用datepicker函数时,无论传递给它的是什么,都将用于初始化小部件.之后,对datepicker的每次其他调用将用于调用方法或设置选项.

First thing to understand is that the first time you call the datepicker function whatever you pass to it will be used to initialize the widget. After that, each additional call to datepicker will be used to call methods or set options.

在您的jsfiddle中,尝试:

In your jsfiddle, try:

$( document ).ready( function() {
    $( "#dob" ).datepicker({
        changeMonth: true,
        changeYear: true
    }).datepicker("option", $.datepicker.regional[ "ar" ]);
});​

通过这种方式,我们使用changeMonthchangeYear的选项来初始化日期选择器.在我们的下一个通话中,我们可以更新一个选项,使其成为区域性的.

In this manner we are initializing the datepicker with the options for changeMonth and changeYear. On our next call we can update an option, making it regional.

这篇关于jQueryUI datepicker:具有本地化功能的月/年菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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