【发布时间】:2012-01-24 09:58:09
【问题描述】:
我使用了各种“修复”来使今天按钮也选择日期,到目前为止,所有这些都在 Firefox 上运行良好,但是当我使用它们时 IE 出现错误。每当我今天单击时,日期就会被选中,输入字段会更新并且日期选择器关闭,但 IE 会立即打开另一个无法关闭的日期选择器,除非您打开新的日期选择器。
这是我使用的带有修复程序的日期选择器代码
var $j = jQuery.noConflict();
$j('#data1, #data2').datepicker({ dayNames: ['Duminica', 'Luni', 'Marti', 'Miercuri', 'Joi', 'Vineri', 'Sambata'], dayNamesMin: ['Du', 'Lu', 'Ma', 'Mi', 'Jo', 'Vi', 'Sa'], firstDay: 1,
monthNames: ['Ianuarie','Februarie','Martie','Aprilie','Mai','Iunie','Iulie','August','Septembrie','Octombrie','Noiembrie','Decembrie'],
monthNamesShort: ['Ian','Feb','Mar','Apr','Mai','Iun','Iul','Aug','Sep','Oct','Noi','Dec'],
showOtherMonths: true,
selectOtherMonths: true,
dateFormat: 'yy-mm-dd',
defaultDate: new Date(),
changeMonth: true,
showButtonPanel: true, currentText: 'Astazi',
changeYear: true
});
我使用的第一个修复:
$j('button.ui-datepicker-current').live('click', function() {
$j.datepicker._curInst.input.datepicker('setDate', new Date()).datepicker('hide');
});
就在我初始化日期选择器之后。
还用
重写了函数var _gotoToday = jQuery.datepicker._gotoToday;
// datepicker is directly inside the jQuery object, so override that
jQuery.datepicker._gotoToday = function(a){
var target = jQuery(a);
var inst = this._getInst(target[0]);
// call the old function, so default behaviour is kept
_gotoToday.call(this, a);
// now do an additional call to _selectDate which will set the date and close
// close the datepicker (if it is not inline)
jQuery.datepicker._selectDate(a,
jQuery.datepicker._formatDate(inst,inst.selectedDay, inst.selectedMonth, inst.selectedYear));
}
也试过只添加
this._setDateDatepicker(target, new Date());
this._selectDate(id, this._getDateDatepicker(target));
在 _gotoToday 函数的末尾
所有这些都完全符合您在 Firefox 中的预期,但在使用 IE 时给我留下了上面提到的问题。
【问题讨论】:
标签: internet-explorer jquery-ui-datepicker