1

使用来自http://trentrichardson.com/examples/timepicker/的日期时间选择器,我必须更改用户单击特定日期时的最大小时数。到目前为止,我的代码进行了 AJAX 调用,并在一天中的每次点击中获得最大小时数(每天的最大小时数不同,并且存在于数据库中)。

现在我试图刷新视图,以便显示更新的 maxhour,但表单重置为“janaury 0”,当我关闭表单并单击它返回最后一个请求的 maxhour(如果应用于选定的任何一天)。

要重置表单,我使用了选项方法,但它不起作用,所以我有一个方法在每个onselect事件上调用,该方法会破坏 datetimepicker 的旧属性并重新制作所有内容并分配属性。

我什至尝试使用应该刷新视图的 datetpicker 的刷新方法。

初始分配

$("#startDate").datetimepicker({
    onSelect: function (date) {
        manipulate(date);
    },
    timeFormat: 'hh:mm:ss tt',
    hourMin: 8,
    hourMax: endHour,
    showSecond: false,
    stepMinute: 15,
    minuteGrid: 5,
    addSliderAccess: true,
    sliderAccessArgs: {
        touchonly: false
    },
    showOn: "button",
    buttonText: "Select a date to check out equipment(s).",
    buttonImage: "../images/calendar.gif",
    buttonImageOnly: true,
    defaultDate: "+0",
    changeMonth: false,
    numberOfMonths: 2,
    minDate: 0,
    maxDate: '+5w',
    beforeShowDay: unavailable,
    ampm: true
});

function manipulate(date) {
    var sendDate = date.toString();
    jQuery.ajax({
        url: "endtime.php",
        data: {
            day: sendDate
        },
        type: "POST",
        success: function (XML) {
            var answer = jQuery("data", XML).text();
            var time = answer.split(":");
            var timetemp = sendDate.split(" ");
            var timenew = timetemp[0] + " " + answer;
            //$("#startDate").datetimepicker.( "option" ,hourMax ,time[0]); this is one of the first approach
            $("#startDate").datetimepicker("destroy");
            //$("#startDate").datetimepicker("refresh");
            var DateOptions = {
                onSelect: function (date) {
                    manipulate(date);
                    //$("#startDate").datetimepicker("refresh");
                    //datepicker._gotoToday('#startDate');
                },
                timeFormat: 'hh:mm:ss tt',
                hourMin: 8,
                hourMax: time[0],
                showSecond: false,
                stepMinute: 15,
                minuteGrid: 5,
                addSliderAccess: true,
                sliderAccessArgs: {
                    touchonly: false
                },
                showOn: "button",
                buttonText: "Select a date to check out equipment(s).",
                buttonImage: "../images/calendar.gif",
                buttonImageOnly: true,
                defaultDate: "+0",
                changeMonth: false,
                numberOfMonths: 2,
                minDate: 0,
                maxDate: '+5w',
                beforeShowDay: unavailable,
                ampm: true,
                setDate: date
            }
            $("#startDate").datetimepicker(DateOptions);
        }
    })
}

任何帮助将不胜感激。

4

0 回答 0