http://jsfiddle.net/k2faz58e/1/
HTML:
<p>Date: <input type="text" id="datepicker"></p>
JQ:
$.datepicker._updateDatepicker_original = $.datepicker._updateDatepicker;
$.datepicker._updateDatepicker = function(inst) {
$.datepicker._updateDatepicker_original(inst);
var afterShow = this._get(inst, 'afterShow');
if (afterShow)
afterShow.apply((inst.input ? inst.input[0] : null)); // trigger custom callback
}
$("#datepicker").datepicker({
afterShow :function(){
var $dp=$("#ui-datepicker-div");
$dp.find('.ui-state-default').each(function(){
var $td=$(this).parents('td');
var month=parseInt($td.attr('data-month'));
month++;
var year=$td.attr('data-year')
var day=parseInt($(this).text());
if(month<10) month='0'+month;
if(day<10) day='0'+day;
var date=year+'-'+month+'-'+day;
$(this).attr('href','mysite.com/look-for-date?date='+date);
});
},
});
解决方案2 - 格targtet
新:http://jsfiddle.net/4p0trbz2/
HTML:
<p>Date: <div id="datepicker"></div></p>
JQ:
$(function() {
//http://stackoverflow.com/questions/6334898/jquery-datepicker-after-update-event-or-equivalent
$.datepicker._updateDatepicker_original = $.datepicker._updateDatepicker;
$.datepicker._updateDatepicker = function(inst) {
$.datepicker._updateDatepicker_original(inst);
var afterShow = this._get(inst, 'afterShow');
if (afterShow)
{
afterShow.apply($("#datepicker")[0]); // trigger custom callback
}
}
$("#datepicker").datepicker({
afterShow :function(){
var $dp=$(".ui-datepicker-inline");
$dp.css("display", "block");
$dp.find('.ui-state-default').each(function(){
var $td=$(this).parents('td');
var month=parseInt($td.attr('data-month'));
month++;
var year=$td.attr('data-year')
var day=parseInt($(this).text());
if(month<10) month='0'+month;
if(day<10) day='0'+day;
var date=year+'-'+month+'-'+day;
$(this).attr('href','mysite.com/look-for-date?date='+date);
}).click(function(){
window.location=$(this).attr('href');
});
},
});
});
不能简单地做我害怕。 Jquery的日期选择器不会派发适当的事件。如果有一个,那么它会被称为'onDateHover'。也许其他一些日期选择器是如此装备。 – 2014-11-05 03:06:04