我正在使用jquery datepicker来显示预订表格的可用预订日期。
datepicker工作正常,但现在显示更长。相反,我收到错误{ Uncaught TypeError:$(...)。datepicker不是函数}。
代码包含在页眉中,据我所知,一直工作正常,直到它不再是随机的。我之前注意到错误,因为我在日历上阻止了一个日期,当我去测试它时它不会出现。
该网站是一个Weebly网站,我正在使用的表单收集条目供我审核。昨晚10点18分(新西兰时间),提交了一个具有正确日期格式的条目,但是下一次预订(新西兰时间下午4:50)输入为“可能是第6天”,表示它是由用户输入的。
我是唯一一个可以访问该网站源代码并且在过去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 :(得分:0)
请检查一下。您的代码无效,因为它阻止了Http的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>
答案 1 :(得分: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)
}
});
&#13;
<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>
&#13;
这里有一个工作日期固定的日期
$(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)
}
});
&#13;
<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">
&#13;