2016-02-29 261 views
0

這裏是我到目前爲止已經試過:如何爲日期選擇器設置最小和最大日期?

Date of birth : <input id="date_of_birth" type="text" /><br /> 

我的Javascript代碼是這樣的:

$(function(){ 

    $('#date_of_birth').datepicker({ 

     monthNames: [ "Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember" ], 
     dayNames: [ "Minggu", "Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu" ], 
     dayNamesMin: [ "M", "S", "S", "R", "K", "J", "S" ], 
     //showOn: 'both', 
     dateFormat: 'yy-mm-dd', 
     changeMonth: true, 
     changeYear: true, 
     inline: true, 
     yearRange: '-100:-12', 
    }); 
}); 

演示是這樣的:http://jsfiddle.net/oscar11/8w8v9/1133/

任何解決方案來解決我的問題呢?

謝謝

+2

我只是看着它 - 它工作正常,當你選擇日期前更改的一年。這是因爲在年份輸入下拉列表中有一個onchange處理程序,我想在沒有對所選選項進行更改的情況下,它是默認的當前年份。 – gavgrif

回答

3
$(function(){ 

    $('#date_of_birth').datepicker({ 

     monthNames: [ "Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember" ], 
     dayNames: [ "Minggu", "Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu" ], 
     dayNamesMin: [ "M", "S", "S", "R", "K", "J", "S" ], 
     dateFormat: 'yy-mm-dd', 
     changeMonth: true, 
     changeYear: true, 
     inline: true, 
     minDate: '-100Y', 
     maxDate: '-12Y', 
    }); 
}); 

more info on datePicker

+0

我需要你幫忙。看看這裏:http://stackoverflow.com/questions/39652796/why-multiple-datepicker-not-working/39652870#39652870 –

0

這對我的作品

$(function(){ 
$('#date_of_birth').datepicker({ 
    //dateFormat: 'dd-mm-yy', 
    //altField: '#thealtdate', 
    //altFormat: 'yy-mm-dd' 

    monthNames: [ "Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember" ], 
      dayNames: [ "Minggu", "Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu" ], 
      dayNamesMin: [ "M", "S", "S", "R", "K", "J", "S" ], 
//      showOn: 'both', 
      dateFormat: 'yy-mm-dd', 
      changeMonth: true, 
      changeYear: true, 
      inline: true, 
      yearRange: (new Date().getFullYear() - 100)+":", 
      maxDate: '-12y' 



});}); 
相關問題