JQuery datePicker 日期重置 [英] JQuery datePicker date reset
本文介绍了JQuery datePicker 日期重置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在日历底部的日期选择器中添加一个重置"控件——关闭"控件所在的位置.这将使用户能够将绑定到 datepicker 的输入重置为空白(无日期).
I would like to add a "Reset" control to the datepicker at the bottom of the calendar - where the "close" control goes. This would enable the user to reset the input tied to datepicker to blank (no date).
我不知道如何编写绑定函数,具体来说,如何获取绑定到控件的元素?
I can't figure out how to write the bind function, specifically, how do I get a hold of the element bound to the control?
if (this.displayClear) {
$pop.append(
$('<a href="#" id="dp-clear">' + $.dpText.TEXT_CLEAR + '</a>')
.bind(
'click',
function()
{
c.clearSelected();
//help! reset the value to '': $(this.something).val('')
c._closeCalendar();
}
)
);
}
推荐答案
这是可行的解决方案,只需在调用 datepicker 之前调用 cleanDatepicker() 即可.
Here is working solution, just call cleanDatepicker() before any call to datepicker.
function cleanDatepicker() {
var old_fn = $.datepicker._updateDatepicker;
$.datepicker._updateDatepicker = function(inst) {
old_fn.call(this, inst);
var buttonPane = $(this).datepicker("widget").find(".ui-datepicker-buttonpane");
$("<button type='button' class='ui-datepicker-clean ui-state-default ui-priority-primary ui-corner-all'>Delete</button>").appendTo(buttonPane).click(function(ev) {
$.datepicker._clearDate(inst.input);
}) ;
}
}
这篇关于JQuery datePicker 日期重置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文