jQuery 打开日期选择器上的“今天”按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17008293/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Turn on Today button on date picker
提问by Alaa
I am using a date picker from this source http://jqueryui.com/datepicker/#buttonbar, I am trying to let "Today" button on the button bar to be active, can any one help me please.
我正在使用来自http://jqueryui.com/datepicker/#buttonbar的日期选择器,我试图让按钮栏上的“今天”按钮处于活动状态,请任何人帮助我。
$(".datepicker").datepicker({
showButtonPanel: true, closeText: 'Clear',
gotoCurrent : true,
changeMonth: true,
changeYear: true,
yearRange: '1900, 2300',
dateFormat: _DateFormatDatePicker,
onSelect: function (dateText, inst) {
dateAsString = dateText; //the first parameter of this function
var dateAsObject = $(this).datepicker('getDate'); //the getDate method
document.getElementById('<%=hdnTempDate.ClientID%>').value = dateText;
}
回答by periback2
Try this:
尝试这个:
$(".datepicker").datepicker({
showOn: "button",
showButtonPanel: true,
buttonImage: buttonCalendar,
buttonImageOnly: true,
buttonText: ""
});
and call this js code in the pages where you have the calendar.
并在您拥有日历的页面中调用此 js 代码。
$.datepicker._gotoToday = function(id) {
$(id).datepicker('setDate', new Date()).datepicker('hide').blur();
};
回答by R M Shahidul Islam Shahed
Try this
尝试这个
$(function() {
$( "#datepicker" ).datepicker({
showButtonPanel: true
});
});
回答by Tahir
Enable the Buttons panel by: showButtonPanel: true
. Then place the following code after your datepicker JS code:
通过以下方式启用按钮面板:showButtonPanel: true
。然后将以下代码放在 datepicker JS 代码之后:
var _gotoToday = jQuery.datepicker._gotoToday;
jQuery.datepicker._gotoToday = function(a){
var target = jQuery(a);
var inst = this._getInst(target[0]);
_gotoToday.call(this, a);
jQuery.datepicker._selectDate(a, jQuery.datepicker._formatDate(inst,inst.selectedDay, inst.selectedMonth, inst.selectedYear));
};