如何在Visual Studio 2010 MVC 2 Web项目中添加jQuery?
问题描述:
可能重复:
Why don't jQuery works in Microsoft Visual Studio 2010?如何在Visual Studio 2010 MVC 2 Web项目中添加jQuery?
我们已经创建了一个网站的Visual Studio 2010 MVC 2的Web项目,现在要添加样式菜单和图像幻灯片使用jQuery。但是,当我们添加jQuery脚本文件时,Visual Studio会返回一些错误。我们已经正确给出了链接jQuery文件的先决条件。但错误依然还是..
// code that we have used in jQuery //
function slideSwitch() {
var $active = $('#Left_Image DIV.active');
if ($active.length == 0) $active = $('#Left_Image DIV:last');
// use this to pull the divs in the order they appear in the markup
var $next = $active.next().length ? $active.next()
: $('#Left_Image DIV:first');
// uncomment below to pull the divs randomly
// var $sibs = $active.siblings();
// var rndNum = Math.floor(Math.random() * $sibs.length);
// var $next = $($sibs[ rndNum ]);
$active.addClass('last-active');
$next.css({ opacity: 0.0 })
.addClass('active')
.animate({ opacity: 1.0 }, 1000, function() {
$active.removeClass('active last-active');
});
}
$(function() {
setInterval("slideSwitch()", 5000);
});
// code in view master page //
<title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>
<link href="../../Content/NIPL.css" rel="Stylesheet" type="text/css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script src="<%= Url.Content("~/Scripts/jquery-1.5.1.min.js") %>" type="text/javascript"></script>
<script src="../../Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
<script src="<%= Url.Content("~/Scripts/SlideShow.js") %>" type="text/javascript"></script>
答
当你创建一个新的MVC2项目,你将有一个名为Script
文件夹拥有jQuery的。非常有趣的是你没有这些脚本。
复制通过拖放&下降jQuery的文件到文件夹Content
夹Scripts
及复印件CSS文件(这是不是里面Script
)
在Content
文件夹,你会看到Site.css
文件。你必须放置CSS文件。
将这些CSS文件的<link href=...
包含在Site.Master文件的标题部分中。
还有从Scripts
文件夹的JavaScript文件。
它会抛出构建错误吗?它究竟说什么?或者在浏览器控制台中显示哪些错误? – 2012-01-09 07:39:07
请只更新您的原始问题,而不是要求一个新的问题。您可以点击标签下的“编辑”链接来执行此操作。 – 2012-01-09 09:16:53