0

我对 javascript 和 jQuery 很陌生。

到目前为止我所拥有的效果很好,但我现在需要根据日期选择更改 [hourMax] 值。Mo-Thu 将是 18,星期五必须是 16 - 我怀疑问题可能是函数 timemax(date)。我还需要删除“现在”按钮。

我怎样才能做到这一点?您的帮助将不胜感激。

<script type="text/javascript">

 $(document).ready(function(){

$("#datetimepicker").datetimepicker({
beforeShowDay: nonWorkingDates,
numberOfMonths: 1,
defaultDate: 1,
firstDay: 0,
minDate: 0,
maxDate: '+60D',
//showAnim: 'slide',
controlType: 'select',
timeFormat: 'h:mm tt',
regional: 'en',
dateFormat: 'DD, MM d, yy',
//altField: '#alternate-datime',
altFormat: 'DD, MM d, yy hh:mm',
separator: ' @ ',
showTime:false,
//timeOnlyTitle: 'Choose Time',
timeText:'Please select \\n Appointment Time',
pickerTimeFormat:'h:mm tt',
currentText:'',
hourText:'',
hourMin:9,
hourMax:timemax,
//timeFormat: 'hh:mm',
//separator: 'T',
showSecond:false,
showMinute:false,
//hourMin: '7',
//hourMax: '13',
//showSecond: false,
//hourGrid: 1,
//minDateTime:9,
//minuteGrid: 30,
stepHour: 1,
//stepMinute: 30,
//stepSecond: 10

});

function nonWorkingDates(date){
var day = date.getDay(), Sunday = 0, Monday = 1, Tuesday = 2, Wednesday = 3, Thursday = 4, Friday = 5, Saturday = 6;
var closedDates = [
[1, 1, 2013, 'us'],
      [1, 21, 2013, 'us'],
      [2, 18, 2013, 'us'],
      [3, 29, 2013, 'us'],
      [5, 27, 2013, 'us'],
      [7, 4, 2013, 'us'],
      [9, 2, 2013, 'us'],
      [9, 5, 2013, 'us'],
      [9, 13, 2013, 'us'],
      [10, 14, 2013, 'us'],
      [11, 11, 2013, 'us'],
      [11, 28, 2013, 'us'],
      [11, 29, 2013, 'us'],
      [12, 24, 2013, 'us'],
      [12, 25, 2013, 'us'],
      [12, 31, 2013, 'us']
];
var closedDays = [[Saturday],[Sunday]];
for (var i = 0; i < closedDays.length; i++) {
if (day == closedDays[i][0]) {
return [false];
}

}

for (i = 0; i < closedDates.length; i++) {
if (date.getMonth() == closedDates[i][0] - 1 &&
date.getDate() == closedDates[i][1] &&
date.getFullYear() == closedDates[i][2]) {
return [false];
}
}

return [true];
}

function timemax(date){
var days = date.getDay(), Sunday = 0, Monday = 1, Tuesday = 2, Wednesday = 3, Thursday = 4, Friday = 5, Saturday = 6;

if(date.getDate() == days[5]){
return [16];
}
else {
return [18];
}
}

});     
        </script>
4

1 回答 1

1

hourMax根据所选日期进行设置:

$("#datetimepicker").datetimepicker({
    ...
    onSelect: function() {
        var day = $(this).datetimepicker("getDate").getDay();
        var maxHour = (day == 5) ? 16 : 18;
        $(this).datetimepicker("option", "hourMax", maxHour);
    }
});

要禁止 Now 按钮,请将其添加到您的 CSS 中:

#datetimepicker .ui-datepicker-current {
    display: none;
}
于 2013-05-06T22:47:33.360 回答