2012-04-13 30 views
39

こんにちは私は(1999-10-25)に私のjqueryのdatepickerの最小日付を設定したいので、私は以下のコードは動作していないしようとしました。それが正常に動作しますよりも、私は2002以上に分年間変更した場合しかし、私は分年を指定した場合、それは、誰かが私を助ける2002.canためにのみ表示されます未満2002 {eexample 1999上記のように}jquery datepickerの最小日付を設定する

$(function() { 
    $('#datepicker').datepicker({ 
     dateFormat: 'yy-mm-dd', 
     showButtonPanel: true, 
     changeMonth: true, 
     changeYear: true, 
     showOn: "button", 
     buttonImage: "images/calendar.gif", 
     buttonImageOnly: true, 
     minDate: new Date(1999, 10 - 1, 25), 
     maxDate: '+30Y', 
     inline: true 
    }); 
}); 

** 。私はjquery-1.7.1.min.jsとjquery-ui-1.8.18.custom.min.jsを使用しています。

答えて

79
$(function() { 
    $('#datepicker').datepicker({ 
     dateFormat: 'yy-mm-dd', 
     showButtonPanel: true, 
     changeMonth: true, 
     changeYear: true, 
yearRange: '1999:2012', 
     showOn: "button", 
     buttonImage: "images/calendar.gif", 
     buttonImageOnly: true, 
     minDate: new Date(1999, 10 - 1, 25), 
     maxDate: '+30Y', 
     inline: true 
    }); 
}); 

追加した年の範囲オプションhttp://jqueryui.com/demos/datepicker/#option-yearRange


は、例を参照してください。それは問題を解決するはずです

+0

おかげで – user1184777

+0

感謝@Gaurv作業それを男。そのうまく動作します。 –

+0

素敵ですよ。 –

1

Hiya 作業デモhttp://jsfiddle.net/femy8/

今のカレンダーは1999年10月25日の最小値になります。

カレンダーのテキストボックスの横にある小さなアイコンをクリックすると表示されます。あなたは1999年まで選択を試みることができますが、選択のための最低限の日付は1999年の25日です。これはあなたが望むものです。

これは役に立ちます。いいですね! :)歓声!

のjQueryコード

$(".mypicker").datepicker({ 
    changeYear: true, 
    dateFormat: 'yy-mm-dd', 
    showButtonPanel: true, 
    changeMonth: true, 
    changeYear: true, 
    showOn: "button", 
     buttonImage: "images/calendar.gif", 
     buttonImageOnly: true, 
     minDate: new Date('1999/10/25'), 
     maxDate: '+30Y', 
     inline: true 
}); 


​ 
13

問題は "yearRange" のデフォルトのオプションは10年であるということです。

従って2012 - 10 = 2002

yearRangeをc-20:cまたは1999(yearRange: '1999:c')に変更し、制限日(mindate、maxdate)と組み合わせて使用​​します。詳細情報については

http://jsfiddle.net/kGjdL/

そしてほかのあなたのコード:

$(function() { 
    $('#datepicker').datepicker({ 
     dateFormat: 'yy-mm-dd', 
     showButtonPanel: true, 
     changeMonth: true, 
     changeYear: true, 
     showOn: "button", 
     buttonImage: "images/calendar.gif", 
     buttonImageOnly: true, 
     minDate: new Date(1999, 10 - 1, 25), 
     maxDate: '+30Y', 
     yearRange: '1999:c', 
     inline: true 
    }); 
}); 
+0

良い簡潔な説明 – sockmonk

0

ちょうど将来のプログラマーのためにこれを追加したいだけです。

このコードは、日付の最小値と最大値を制限します。 現在の年を最大年とすることで、年は完全に制御されます。

これは誰にも役立つと願っています。

ここにコードがあります。

var dateToday = new Date(); var yrRange = '2014' + ":" +(dateToday。getFullYear());

$(function() { 
    $("[id$=txtDate]").datepicker({ 
     showOn: 'button', 
     changeMonth: true, 
     changeYear: true, 
     showButtonPanel: true, 
     buttonImageOnly: true, 
     yearRange: yrRange, 
     buttonImage: 'calendar3.png', 
     buttonImageOnly: true, 
     minDate: new Date(2014,1-1,1), 
     maxDate: '+50Y', 
     inline:true 
    }); 
}); 
0

この

<script> 

    $(document).ready(function(){ 
      $("#order_ship_date").datepicker({ 
      changeMonth:true, 
      changeYear:true,   
      dateFormat:"yy-mm-dd", 
      minDate: +2, 
     }); 
    }); 


</script> 

HTMLコードを

<input id="order_ship_date" type="text" class="input" style="width:80px;" /> 
+1

あなたが提供するソリューションについてもう少し詳しく説明してください。 – abarisone

0

の下に与えられているようにあなたは、すでに今年の範囲を指定した場合、基本的には唯一の年がある場合mindatemaxdateを使用する必要はありません試してみてください必要があります。

2

分、日付、最後の3ヶ月とmax日付次の3ヶ月

$('#id_your_date').datepicker({ 
    maxDate: '+3m', 
    minDate: '-3m' 
}); 
関連する問題