我正在尝试将 fullcalendar 和 datepicker 链接在一起,为我自己形成一个漂亮的日历,但我的代码遇到了以下错误:
错误信息:
$("#datepicker").datepicker is not a function
这是我的代码:
<link rel='stylesheet' type='text/css' href='../fullcalendar/fullcalendar.css' />
<link rel='stylesheet' type='text/css' href='../fullcalendar/fullcalendar.print.css' media='print' />
<link href="../scripts/jquery-ui-1.7.3.custom.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="../Styles/dark-hive/jquery.ui.all.css">
<script src="../jquery/jquery-1.7.1.js"></script>
<script type='text/javascript' src='../jquery/jquery-ui-1.8.17.custom.min.js'></script>
<script src="../jquery/ui/jquery.ui.core.js"></script>
<script src="../scripts/ui/jquery.ui.datepicker.js"></script>
<script type='text/javascript' src='../fullcalendar/fullcalendar.min.js'></script>
<script type='text/javascript'>
$(function() {
$('#calendar').fullCalendar({
theme: true,
header: {
left: '',
center: '',
right: ''
},
defaultView: 'agendaDay',
editable: false,
events: "../fullcalendar/JSONcreator"
});
$('#datepicker').datepicker({
inline: true,
onSelect: function(dateText, inst) {
var d = new Date(dateText);
$('#calendar').fullCalendar('gotoDate', d);
}
});
})
</script>
还有,有什么方法可以去掉顶部的一些 JQuery 脚本调用吗?太多了,看起来太乱了,但我是 JQuery 的新手。
最佳答案
您正在加载 fullcalendar.min.js
在页面加载之前 jquery-1.7.1.js
, jquery.ui.core.js
和 jquery.ui.datepicker.js
.放在它们下面,否则无法扩展它们的功能。
您还可以通过将 jQuery 函数放在一个中来减少代码 <script>
标签而不是两个:
<script type='text/javascript'>
$(function() {
$('#calendar').fullCalendar({
theme: true,
header: {
left: '',
center: '',
right: ''
},
defaultView: 'agendaDay',
editable: false,
events: "../fullcalendar/JSONcreator"
});
$('#datepicker').datepicker({
inline: true,
onSelect: function(dateText, inst) {
var d = new Date(dateText);
$('#calendar').fullCalendar('gotoDate', d);
}
});
})
</script>
关于javascript - $ ("#datepicker").datepicker 不是函数 - JavaScript 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9468566/