我正在为项目使用jQuery UI Datepicker,但是当用户点击它时,需要今天按钮在文本字段中输入日期.默认情况下,它只选择日期,但不会将其输入到字段中.我猜这只需要我的jQuery UI文件的快速模式,但我会改变什么?谢谢.
编辑:我试过这个:http://dev.jqueryui.com/ticket/4045但它不起作用!
jac*_*cnr 19
我在这里找到了一个解决方案:http://forum.jquery.com/topic/jquery-ui-datepicker-today-button.只需使用这个jQuery片段(我只是用我的datepicker初始化代码):
$('button.ui-datepicker-current').live('click', function() {
$.datepicker._curInst.input.datepicker('setDate', new Date()).datepicker('hide');
});
Run Code Online (Sandbox Code Playgroud)
我唯一的问题是,点击"今天"按钮后,焦点将保留在输入框中,这意味着您无法再次单击它以选择其他日期.这可以通过后缀blur()修复:
$('button.ui-datepicker-current').live('click', function() {
$.datepicker._curInst.input.datepicker('setDate', new Date()).datepicker('hide').blur();
});
Run Code Online (Sandbox Code Playgroud)
我也不喜欢"今天"按钮上的样式 - 也许它只是我的主题或其他东西,但是今天的按钮与"完成"按钮相比有点灰色.这可以通过以下CSS修复(可能因主题不同而有所不同,我不确定):
/* 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);
}
Run Code Online (Sandbox Code Playgroud)
我意识到这是一个迟到的回复,但我只是遇到了这个问题,证明解决方案就像一个魅力.
但是,按钮样式问题是由jQuery ui类引起的.我将以下代码添加到日期文本输入的单击操作中:
$('.date').click(function() {
$('button.ui-datepicker-current').removeClass('ui-priority-secondary').addClass('ui-priority-primary');
});
Run Code Online (Sandbox Code Playgroud)
这将删除错误的类,并将正确的类添加到按钮,使其与"完成"按钮相同.你正在使用什么主题并不重要.为了完整性,这是我的整个代码:
$('.date').datepicker({
dateFormat: 'yy-mm-dd',
showButtonPanel: true
}).click(function() {
$('button.ui-datepicker-current').removeClass('ui-priority-secondary').addClass('ui-priority-primary');
});
$('button.ui-datepicker-current').live('click', function() {
$.datepicker._curInst.input.datepicker('setDate', new Date()).datepicker('hide').blur();
});
Run Code Online (Sandbox Code Playgroud)
只需添加一个<input type="text" class="date" value="" />,就可以了.
| 归档时间: |
|
| 查看次数: |
11101 次 |
| 最近记录: |