2017-04-12 47 views
1
$('#toDate').change(function() { 
    selectedToDate = $('#toDate').val(); 
    var year = selectedToDate.substring(6, 10); 
    var day = selectedToDate.substring(3, 5); 
    var month = selectedToDate.substring(0, 2); 
    $('#fromDate').datepicker({ 
     minDate: new Date(year, month-1, day), 
     inline: true 
    }); 

}); 

Iam試圖禁用日曆的過去日期。但我的代碼不起作用。內置日期選擇器功能不起作用

+0

'destroy'的插件,並用新值重新初始化。有關如何銷燬的信息,請參閱插件文檔。 –

+0

你可以發佈你的整個代碼 –

回答

1

請儘量使用$("#fromDate").datepicker("option", "minDate", new Date(year, month-1, day));

$('#toDate').change(function() { 
 
    selectedToDate = $('#toDate').val(); 
 
    var year = selectedToDate.substring(6, 10); 
 
    var day = selectedToDate.substring(3, 5); 
 
    var month = selectedToDate.substring(0, 2); 
 
     
 
    
 
    $("#fromDate").datepicker("option", "minDate", new Date(year, month-1, day)); 
 
    /*$('#fromDate').datepicker({ 
 
     minDate: new Date(2017, 3, 15), 
 
     inline: true 
 
    });*/ 
 

 
})
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> 
 
    <link rel="stylesheet" href="/resources/demos/style.css"> 
 
    <script src="https://code.jquery.com/jquery-1.12.4.js"></script> 
 
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> 
 
    <script> 
 
    $(function() { 
 
    $("#toDate").datepicker(); 
 
    $("#fromDate").datepicker(); 
 
    }); 
 
    </script> 
 
    
 
<p>Date: <input type="text" id="toDate"></p> 
 
<p>To:<input type="text" id="fromDate"></p> 
 

 

 

 
    
 

0

$('#datepicker').datepicker({ minDate: 0 });
body { 
 
    font-size: 12px; /* just so that it doesn't default to 16px (which is kinda huge) */ 
 
}
<!-- load jQuery and jQuery UI --> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script> 
 

 
<!-- load jQuery UI CSS theme --> 
 
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css"> 
 

 
<!-- the datepicker input --> 
 
<input type='text' id='datepicker' placeholder='Select date' />

相關問題