我包含我的datepicker輸入內部if語句,所以它不起作用。我不知道它是否因if語句或其他原因而不工作,但是當沒有if語句時,datepicker可以正常工作。腳本包含在正確的順序,所以這很好。 jQuery的腳本:jQuery datepicker不工作 - Laravel應用程序
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<script>
$(function() {
$('#nextDate').datepicker({
dateFormat: "yy-mm-dd",
});
$("#currentDate").datepicker({
dateFormat: "yy-mm-dd",
minDate: 0,
onSelect: function(date){
var date2 = $('#currentDate').datepicker('getDate');
date2.setDate(date2.getDate()+7);
$('#nextDate').datepicker('setDate', date2);
}
});
});
</script>
其中日期選擇應該是頁,站在這樣的:
if(Auth::user()->role == 2) { ?>
<form class="form-horizontal" method="POST" action="/rentals">
{{ csrf_field() }}
<div class="form-group">
<div class="col-sm-5 col-sm-offset-1">
<input class="form-control" type="text" id="currentDate" name="start">
</div>
<div class="col-sm-5">
<input class="form-control" type="text" id="nextDate" name="end">
</div>
</div>
<button type="submit" class="btn btn-success">Rent it</button>
</form>
<?php } ?>
角色很好。我看到輸入框,但是當我點擊輸入框時,日期選擇器不會出現。 – Irfan
不是真的,但當我鍵入jqueryUI包括,它說它沒有加載,但仍然當我刪除如果語句,它工作正常... – Irfan
當我在控制檯中鍵入$ .ui,它說它沒有加載 – Irfan