在我的网页中,我有一个jquery日历来选择多个日期。当我选择每个日期时,日历将刷新以突出显示所选日期。现在的问题是每次我选择日期时页面也会页面顶部。如何让页面保持原位并一次又一次地选择日期..?
这是我的js
$( "#datepickerr" ).datepicker({
dateFormat: 'yy-mm-dd' ,
dayNamesMin: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
todayHighlight: true,
// showButtonPanel: true,
beforeShowDay: function ( date ) {
if(date.getTime() >= date1 && date.getTime() <= date2){
return[true,'date-range',''];
}
else{
return [true, ( (date.getTime() >= Math.min(prv, cur) && date.getTime() <= Math.max(prv, cur)) ? 'date-range' : '')];
}
},
onSelect: function ( dateText, inst ) {
var d1, d2;
prv = cur;
cur = (new Date(inst.selectedYear, inst.selectedMonth, inst.selectedDay)).getTime();
if ( prv == -1 || prv == cur ) {
prv = cur;
date1=date2=prv ;
$('#datepickerr').val( dateText );
$('#datepickerr').datepicker("refresh");
} else {
d1 = $.datepicker.formatDate( 'yy-mm-dd', new Date(Math.min(prv,cur)), {} );
d2 = $.datepicker.formatDate( 'yy-mm-dd', new Date(Math.max(prv,cur)), {} );
date1=d1;
date=d2;
$('#datepickerr').val( d1+' '+d2 );
$('#datepickerr').datepicker("refresh");
}
hideDatepicker(null);
}
});
答案 0 :(得分:-1)
一般想法
var selected = [];
$("#datepickerr").datepicker({
onSelect: function(dateText, inst) {
var index = selected.indexOf(dateText);
if (index !== false) {
$('.d-' + dateText).removeClass('selected');
selected.splice(index, 1);
} else {
$('.d-' + dateText).addClass('selected');
selected.push(dateText)
}
}
});
.selected {
/* your highlight style */
}
<!-- <tag class="d-dateText"><tag class="d-dateText"><tag class="d-dateText"><tag class="d-dateText"> -->