有没有办法处理在jquery UI DatePicker中按下"完成"按钮的事件?
我有一个日期选择器,只允许在这里选择年和月
问题是使用onclose事件阻止我清除字段(如果我点击弹出的日期选择器,那么如果我关闭当前选定的月份和年份将被放入该字段).
我不想在日期选择器之外使用额外的"清除"按钮,所以我可以使用完成按钮.
当"完成"按钮调用_hideDatepicker函数时,您可以覆盖它:
jQuery.datepicker._hideDatepicker = function() {
alert('hello');
};
Run Code Online (Sandbox Code Playgroud)
这是完美的解决方案:
$(function() {
$('.monthYearPicker').datepicker({
changeMonth: true,
changeYear: true,
showButtonPanel: true,
dateFormat: 'MM yy'
}).focus(function() {
var thisCalendar = $(this);
$('.ui-datepicker-calendar').detach();
$('.ui-datepicker-close').click(function() {
var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
thisCalendar.datepicker('setDate', new Date(year, month, 1));
});
});
});
Run Code Online (Sandbox Code Playgroud)
CSS:
.ui-datepicker-calendar {
display: none;
}
Run Code Online (Sandbox Code Playgroud)
和HTML:
<label for="myDate">Date :</label>
<input name="myDate" class="monthYearPicker">
Run Code Online (Sandbox Code Playgroud)
看看它在这个jsfiddle中是如何工作的.
资料来源: http ://develop-for-fun.blogspot.com/2013/08/jquery-ui-datepicker-month-and-year.html
我在一个论坛上找到了解决方案(不记得哪里 - 对不起).我知道它已经有一段时间了,但是对于未来的搜索:)
注意:需要在插件中完成更改.您只需搜索"onClose:"即可找到它.
onClose: function (dateText, inst) {
function isDonePressed() {
return ($('#ui-datepicker-div').html().indexOf('ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all ui-state-hover') > -1);
}
if (isDonePressed()){
alert('done pressed');
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16612 次 |
| 最近记录: |