2 回答

TA貢獻1856條經驗 獲得超11個贊
乍一看,這似乎是日期不匹配的問題。如果您使用下面的示例,您可以看到來自 API 的數據應該是什么樣子。
var msg = ["2020-05-11"];
$('#appointment_datepicker').datepicker({
beforeShowDay: function(date) {
var day = jQuery.datepicker.formatDate('yy-mm-dd', date);
return [msg.indexOf(day) == -1]
}
});
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.0/themes/smoothness/jquery-ui.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js" integrity="sha256-eGE6blurk5sHj+rmkfsGYeKyZx3M4bG+ZlFyA7Kns7E=" crossorigin="anonymous"></script>
<input class="form-control" id="appointment_datepicker" name="appointment_datepicker" type="text" placeholder="Select Date">

TA貢獻1779條經驗 獲得超6個贊
這里每天都有一個固定號碼,例如
Sunday = 0
Monday = 1
Tuesday = 2
Wednesday = 3
Thursday = 4
Friday = 5
Saturday = 6
所以Array一天的數字(例如:var arr = [1, 2, 3];)從控制器返回,那一天將在datepicker.
只需在 Ajax 中更改以下代碼
阿賈克斯
var arr = [1, 2, 3] //these are the array of days numbers return from controller
$('#appointment_datepicker').datepicker('option', 'beforeShowDay', function(date){
var day = date.getDay();
return [(arr.indexOf(day) != -1)];
});
所以只在這里Monday,Tuesday并將Wednesday在日歷中激活datepicker。
- 2 回答
- 0 關注
- 211 瀏覽
添加回答
舉報