0

我尝试添加dateFormat: "dd-mm-yy",但其余功能不起作用。然后我尝试全局更改格式,

 $.datepicker.setDefaults({dateFormat: 'dd-mm-yy'});

但它也没有奏效。我正在使用 jquery-1.9.1 和 jquery-ui-1.10.3。

$(document).ready(function formUi() {
    var dateToday = new Date();
    $("#datepicker-round-trip-1").datepicker({
        numberOfMonths: 2,
        showButtonPanel: true,
        changeMonth: true,
        changeYear: true,
        inline: true,
        maxDate: new Date(new Date($('datepicker-round-trip-2').val()).valueOf()),
        beforeShow: function () {
            if ($("#datepicker-round-trip-1").val() == "" && $("#datepicker-round-trip-2").val() == "") {
                $("#datepicker-round-trip-1").datepicker('option', { minDate: dateToday, maxDate: null });
            }
            else {
              $("#datepicker-round-trip-1").datepicker('option', { minDate: dateToday });
            }
        },
        onSelect: function (dateText, inst) {
            var currentDate = new Date(dateText);
            var valueofcurrentDate = currentDate.valueOf();
            var newDate = new Date(valueofcurrentDate);
            $("#datepicker-round-trip-2").datepicker("option", "minDate", newDate);
        }
    });

    $("#datepicker-round-trip-2").datepicker({
        numberOfMonths: 2,
        showButtonPanel: true,
        changeMonth: true,
        changeYear: true,
        inline: true,
        minDate: new Date(new Date($('#datepicker-round-trip-2').val()).valueOf()),
        beforeShow: function () {
            if ($("#datepicker-round-trip-1").val() == "" && $("#datepicker-round-trip-2").val() == "") {
                $("#datepicker-round-trip-2").datepicker('option', { minDate: dateToday, maxDate: null });
            }
        },
        onSelect: function (dateText, inst) {
            var currentDate = new Date(dateText);
            var valueofcurrentDate = currentDate.valueOf();
            var newDate = new Date(valueofcurrentDate);
            $("datepicker-round-trip-1").datepicker("option", "maxDate", newDate);
        }
    });
});

该脚本只是将日期选择器的 minDate 设置为在前一个日期选择器中选择的最后一个日期。任何帮助或指导表示赞赏:)

4

1 回答 1

0

试试这个: http: //jsfiddle.net/MXstJ/ http://jsfiddle.net/gc4nM/

有用的链接:http: //jqueryui.com/datepicker/

希望这适合你的事业:)

代码

$('#z').datepicker({
    inline: true,
    altField: '#d',
    dateFormat: 'dd-mm-yy',
    defaultDate: new Date()
});
于 2013-10-13T22:07:40.120 回答