1

私はhtmlでJqueryカレンダーを持っています。開始日と終了日を表示します。以下は私のコードです:

HTML ヘッド セクションのコード:

<link rel="stylesheet" href="jquery/jquery.ui.all.css">
<script src="jquery/jquery-1.9.1.js"></script>
<script src="jquery/jquery.ui.core.js"></script>
<script src="jquery/jquery.ui.widget.js"></script>
<script src="jquery/jquery.ui.datepicker.js"></script>
<link rel="stylesheet" href="../demos.css">


<script>

$(function() {
    $( "#from" ).datepicker({
        defaultDate: "+1w",
        changeMonth: true,
        numberOfMonths: 1,
        onClose: function( selectedDate ) {
            $( "#to" ).datepicker( "option", "minDate", selectedDate );


        }
    });
    $( "#to" ).datepicker({
        defaultDate: "+1w",
        changeMonth: true,
        numberOfMonths: 1,
        onClose: function( selectedDate ) {
            $( "#from" ).datepicker( "option", "maxDate", selectedDate );
        }
    });
});
</script>

HTML本文コード:

<label for="from">From</label>
<input type="text" id="from" name="from" class="tr"/>
<label for="to">to</label>
<input type="text" id="to" name="to" class="tr"/>

まあ、うまくいっています。しかし、からのファイル名に過去の月を無効にすることは可能ですか? ユーザーが前の月をfromフィールドに選択できないようにしたいだけです。

現在のカレンダーの動作: ユーザーが開始日、つまり 18-05-2013 を選択した場合、終了日は 2013 年 5 月 18 日から始まります。

4

1 に答える 1

2

mindate パラメータを使用する必要があります

$( "#from" ).datepicker({
    defaultDate: "+1w",
    changeMonth: true,
    numberOfMonths: 1,
    minDate: new Date(), // <-------- this will disable all dates prior to the date passed there.
    onClose: function( selectedDate ) {
        $( "#to" ).datepicker( "option", "minDate", selectedDate );


    }
});
于 2013-05-18T08:18:07.507 に答える