2017-05-06 146 views
0

我正在使用jquery datepicker來顯示預訂表單的可用預訂日期。JQuery Datepicker已停止工作?

datepicker一直工作正常,但現在它現在顯示更長。相反,我得到一個錯誤{Uncaught TypeError:$(...)。datepicker不是函數}。

該代碼包含在頁眉中,並且據我所知一直工作正常,直到它只是隨機不再。之前我注意到了這個錯誤,因爲我在日曆上封鎖了一個日期,並且當我去測試時它不會出現。

該網站是一個Weebly網站,我正在使用的表格收集條目供我審閱。在昨晚10點18分(新西蘭時間),一個條目以正確的日期格式提交,但是下一個預訂(新西蘭時間下午4:50)被輸入爲「may 6th」,表示它是用戶輸入的。

我是唯一一個可以訪問該網站源代碼的人,並且在過去2個月中沒有做任何更改(因爲我在復活節前封鎖了一些日期)。我真的不知道爲什麼它會停止工作。

CODE

<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /> 
    <link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel = "stylesheet"> 
<script src="http://code.jquery.com/jquery-1.12.4.js"></script> 
    <script src="http://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> 

     <!-- Javascript --> 
     <script> 

var dateToday = new Date(); 
var array = ["05/05/2017","06/05/2017"] 
$(function() {$("#input-806171099542486857").datepicker({ 
    dateFormat: 'dd/mm/yy', 
    beforeShowDay: function(date) { 
    var string = jQuery.datepicker.formatDate('dd/mm/yy', date); 
    var day = date.getDay(); 
    return [(day != 1 & day != 2) & array.indexOf(string) == -1 ]; 
}, minDate: dateToday 
}); 
}); 

     </script> 

</head> 
+0

嘗試添加HTTPS來的jQuery和jQuery UI的鏈接 –

+1

檢查,如果你不包括jQuery的不止一次 –

+0

它的工作很好,只是使用https https://jsfiddle.net/bfq6pLvc/ –

回答

0

請檢查。您的代碼不能正常工作,因爲它通過Https阻止Http請求。我修改了它,現在它工作正常。

var dateToday = new Date(); 
 
var array = ["05/05/2017","06/05/2017"] 
 
$(function() {$("#input").datepicker({ 
 
    dateFormat: 'dd/mm/yy', 
 
    beforeShowDay: function(date) { 
 
    var string = jQuery.datepicker.formatDate('dd/mm/yy', date); 
 
    var day = date.getDay(); 
 
    return [(day != 1 & day != 2) & array.indexOf(string) == -1 ]; 
 
}, minDate: dateToday 
 
}); 
 
});
<html> 
 
<head> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
 
<link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel = "stylesheet"> 
 
<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> 
 

 
</head> 
 
<body> 
 
<input id="input" type="text" /> 
 

 

 
</body> 
 
</html>

+0

嘿,謝謝你的建議,但我仍然得到同樣的錯誤。 – Wompguinea

0

這裏有一個對多個日期

$(document).ready(function(){ 
 
var array_names = ["John", "Joseph", "Luis"]; 
 
var dbDate; 
 
var date2; 
 
var num = array_names.length; 
 
var array_dates =["1974-05-30", "1978-11-12", "1980-12-11"]; 
 
for(var i = 0; i<num; i++){ 
 
    $("#share").append('<form id = "form_'+array_names[i]+'">'); 
 
    $("#form_"+array_names[i]).append('<input type="text" placeholder="Name" name="routename" value = "'+array_names[i]+'" id="name_'+array_names[i]+'">'); 
 
    $("#form_"+array_names[i]).append('<input type="date" placeholder="Date of birth" name="date_birth" value = "'+array_dates[i]+'" id="datepiker_'+array_names[i]+'" class = "datepiker">'); 
 
    dbDate = array_dates[i]; 
 
    date2 = new Date(dbDate); 
 
    $("#datepiker_"+array_names[i]).datepicker({ 
 
     dateFormat: 'dd-mm-yy' 
 
    }).datepicker('setDate', date2) 
 
} 
 
    
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<meta charset="utf-8"> 
 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
 
     <title>jQuery UI Datepicker - Default functionality</title> 
 
     <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> 
 
    <div id = "share"> 
 
    </div> 
 

 

在這裏工作,你有一個工作固定數量的日期

$(document).ready(function(){ 
 
var dbDate; 
 
var date2; 
 
var array_dates =["1974-05-30", "1978-11-12", "1980-12-11"]; 
 
    var num = array_dates.length; 
 
for(var i = 0; i<num; i++){ 
 
    dbDate = array_dates[i]; 
 
    date2 = new Date(dbDate); 
 
    $("#datepiker_"+i).datepicker({ 
 
     dateFormat: 'dd-mm-yy' 
 
    }).datepicker('setDate', date2) 
 
} 
 
    
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<meta charset="utf-8"> 
 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
 
     <title>jQuery UI Datepicker - Default functionality</title> 
 
     <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> 
 
    <input type ="datepicker" id = "datepiker_0" value = "" class = "datepicker"> 
 
    <input type ="datepicker" id = "datepiker_1" value = "" class = "datepicker"> 
 
    <input type ="datepicker" id = "datepiker_2" value = "" class = "datepicker">