jQuery UI Datepicker今天链接 [英] jQuery UI Datepicker Today Link

查看:47
本文介绍了jQuery UI Datepicker今天链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为项目使用jQuery UI Datepicker,但是当用户单击日期时,需要使用Today按钮将日期输入到文本字段中.默认情况下,它仅选择日期,但不将其输入到字段中.我猜想这将只需要快速修改我的jQuery UI文件,但是我该如何更改?谢谢.

I'm using the jQuery UI Datepicker for a project, but need the today button to enter the date into the textfield when a user clicks on it. By default it just selects the date but doesn't enter it into the field. I'm guessing this will just require a quick mod of my jQuery UI file, but what do I change? Thanks.

我尝试过: http://dev.jqueryui.com/ticket/4045但它不起作用!

I tried this: http://dev.jqueryui.com/ticket/4045 but it doesn't work!

推荐答案

我在这里找到了可行的解决方案:

I found a solution that works here: http://forum.jquery.com/topic/jquery-ui-datepicker-today-button. Just use this snippet of jQuery (I just put it in with my datepicker init code):

$('button.ui-datepicker-current').live('click', function() {
    $.datepicker._curInst.input.datepicker('setDate', new Date()).datepicker('hide');
});

我唯一遇到的问题是,在单击今天"按钮后,焦点仍将保留在输入框中,这意味着您无法再次单击它来选择其他日期.可以通过在后缀blur()来解决此问题:

The only problem I had was that focus would remain in the input box after clicking the "today" button, which means you cant click it again to select a different date. This can be fixed by suffixing blur():

$('button.ui-datepicker-current').live('click', function() {
    $.datepicker._curInst.input.datepicker('setDate', new Date()).datepicker('hide').blur();
});

我也不喜欢今天"按钮上的样式-也许仅仅是我的主题之类的东西,但是与完成"按钮相比,今天"按钮是灰色的.可以使用以下CSS来解决此问题(我不确定,具体主题可能有所不同):

I also didn't like the styling on the "today" button - maybe it was just my theme or something, but the today button was kind of greyed out compared to the "done" button. This can be fixed with the following CSS (may vary for different themes, i'm not sure):

/* This edit gives five levels of specificity, thus making it override other styles */
.ui-datepicker div.ui-datepicker-buttonpane button.ui-datepicker-current {
    font-weight: bold;
    opacity: 1;
    filter:Alpha(Opacity=100);
}

这篇关于jQuery UI Datepicker今天链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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