JQuery DatePicker添加初始'请选择'值

时间:2014-01-27 12:47:04

标签: jquery datepicker

我已设法在this example上创建DatePicker控件,该控件会删除控件以仅显示monthyear范围。

我现在需要在select列表的顶部添加“请选择”选项 - 但是它们没有IDs或我知道推送值的任何方式。

有人可以帮助我把我的大脑包裹起来吗?

来自JSFiddle:

.ui-datepicker-calendar {
    display: none !important;
}

.ui-datepicker-next {
    display: none !important;
}

.ui-datepicker-prev {
    display: none !important;
}

.ui-datepicker-buttonpane {
    display: none !important;
}

.ui-datepicker-header {
    background: none!important;
    border: none!important;
}

.ui-datepicker-title {
    width: 100%;
    margin: 0 !important;
}

$('#startDate').datepicker({
            yearRange: "1900:c",
            changeDay: false,
            changeMonth: true,
            changeYear: true,
            dateFormat: 'MM yy',
            onChangeMonthYear: function (year, month) {
                $("#startYear").val(year);
                $("#startMonth").val(month);
            }
        });

<div id="startDate"></div>

1 个答案:

答案 0 :(得分:1)

使用此文件准备就绪:

$(".ui-datepicker-month").prepend("<option value='' selected='selected'>Select Option</option>");

$(".ui-datepicker-year").prepend("<option value='' selected='selected'>Select Option</option>");

<强> Working Fiddle