$(“#日期选择器”)日期选择器是不是一个函数 - JavaScript错误
我试图fullcalendar和日期选择器连接在一起,形成了自己一个很好的日历,但我遇到了下面的错误与我的代码:
错误信息:
$( “#日期选择器”)日期选择器是不是一个函数
这里是我的代码:
<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>
感谢您的回答!我现在更新了上面的代码,但同样的问题仍然存在! – 2012-02-27 16:57:02
尝试清除缓存。使用Firebug或Chrome的Inspect Element工具来找出你的JavaScript出错的地方。如果它说'$(“#datepicker”)。datepicker不是一个函数',它通常意味着你的内联JavaScript函数没有连接到你的外部jQuery库 – hohner 2012-02-27 17:05:35
这是真的,工作谢谢..... .. – normalUser 2014-04-03 14:24:04
您可以巩固你的jQuery这样:
$(document).ready(function() {
// fullCalendar
$('#calendar').fullCalendar({
theme: true,
header: {
left: '',
center: '',
right: ''
},
defaultView: 'agendaDay',
editable: false,
events: "../fullcalendar/JSONcreator"
});
// jQuery UI datepicker
$('#datepicker').datepicker({
inline: true,
onSelect: function(dateText, inst) {
var d = new Date(dateText);
$('#calendar').fullCalendar('gotoDate', d);
}
});
});
您应该只有一个$(document).ready(function() {});
声明。将其保存在底部的<script>
标签内。这是一样的,要求load
事件侦听器这样:window.addEventListener('load', function(){}, false);
同时,确保之前声明它们的脚本加载。
可能的重复http://*.com/questions/1212696/jquery-ui-datepicker-datepicker-is-not-a-function – 2012-02-27 16:35:34
这是一个不同的问题。 – 2012-02-27 16:37:50
不应该在您的fullcalendar插件之前加载jquery吗? – 2012-02-27 16:38:14