FullCalendar 错误 - Microsoft JScript 运行时错误:对象不支持此属性或方法
我试图将 FullCalendar 硬塞到入门 ASP.NET MVC3 网站中作为试用,但收到错误消息“Microsoft JScript 运行时错误:对象不支持此属性或方法”。生成网页的代码
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' type='text/css' href='~/Content/fullcalendar.css' />
<link rel='stylesheet' type='text/css' href='~/Content/fullcalendar.print.css' media='print' />
<script type='text/javascript' src='~/Scripts/fullcalendar.js'></script>
<script type='text/javascript' src='~/Scripts/gcal.js'></script>
<style type='text/css'>
body {
margin-top: 40px;
text-align: center;
font-size: 14px;
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
}
#calendar {
width: 725px;
margin: 0 auto;
}
</style>
<title>Event Calendar</title>
<link href="../Content/Site.css" rel="stylesheet" type="text/css" />
<script src="/Scripts/jquery-1.4.4.js" type="text/javascript"></script>
</head>
<body>
<div class="page">
<div id="header">
<div id="title">
<h1>My MVC Application</h1>
</div>
<div id="logindisplay">
[ <a href="/Account/LogOn">Log On</a> ]
</div>
<div id="menucontainer">
<ul id="menu">
<li><a href="/Club/EventCalendar">Event Calendar</a></li>
<li><a href="/">Home</a></li>
<li><a href="/Home/About">About</a></li>
</ul>
</div>
</div>
<div id="main">
<div id="pageContent">
<script type="text/javascript">
$(document).ready(function () {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,basicWeek,basicDay'
},
editable: true,
events: [
{
title: 'Lunch',
start: new Date(y, m, d, 12, 0),
end: new Date(y, m, d, 14, 0),
allDay: false
}
]
});
});
</script>
<div id="calendar">
</div>
</div>
<div id="linkContent" >
</div>
</div>
<div id="footer">
</div>
</div>
</body>
</html>
运行 javascript 代码来创建日历时失败。据我所知,许多网站上都显示了该代码。任何人都知道可能出了什么问题。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要在插件之前导入 jQuery。将加载 jQuery 的
标记放在
的顶部。
You need to import jQuery before the plugin. Put the
<script>
tag that loads jQuery up at the top of the<head>
.伙计.. 就像@pointy 所说的.. fullCander 需要 jQuery 才能发挥其魔力..
将所有导入放在顶部 - 顺序很重要!例如,对 CSS 进行分组,然后对 Sctipts 进行分组。以后更容易阅读
编辑
图片价值一千字!我得到了你制作的迷你网站的
似乎根本找不到脚本。!
Ya man.. like @pointy says.. fullCalnder needs jQuery before it can do its magic..
Keep all your imports on the top - order is important! Group CSS then Sctipts for example. Easier to read later
EDIT
Picture worth a thousand words!I got this of the mini site you made
It seems like it cannot find the scripts at all.!
Pointy 关于顺序的说法是正确的,并确保在引用完整日历之前引用了 Jquery。就我而言,我已经正确完成了这一点,但另外我还在标题后面添加了部分视图。部分视图再次引用了 Jquery,然后在执行时抛出了同样的错误。
我只是想我会将其添加为答案,因为它让我寻找了一段时间才弄清楚发生了什么(因为我的头部确实有正确的顺序 - 就像 pointy 的 anser 建议你应该有的那样)。
再说一次,不要试图从其他正确的答案中拿走任何东西。只是添加具体显示错误的内容 - 当我似乎已经完成所有正确的操作时 - 但仍然出现错误。
我的解决方案是将 jquery 引用从部分视图中取出。 (不需要,因为主视图已经有参考)
Pointy is correct about the order, and to make sure you have the Jquery referenced BEFORE you reference the full calendar. In my case, I had done that correctly, but additionally I had added a partial view in after the header. The partial view had a reference to Jquery again, which then threw this same error on execution.
I just thought I would add this as an answer, because it had me looking for a while before I figured out what was going on (because my head section did have the correct order - just like pointy's anser suggests you should have).
Again, not trying to take anything away from the other answer that is correct. Just adding what specifically had the error show up for me -when it seemed I had done everything correct - and still got the error.
The resolution for me was to take the jquery reference out of the partial view. (it wasn't needed because the master view already had the reference)