我正在尝试在我的项目中使用手风琴。据我所知,应该在布局页面添加javascript链接,在索引页面中添加javascript代码,必须在其中显示。 但是浏览器说$(#“手风琴”)。手风琴不是一个功能。 这是_Layout的代码。
@using kazwaySite
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>@ViewBag.Title - My ASP.NET MVC Application</title>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta name="viewport" content="width=device-width"
@Styles.Render("~/Content/themes/base/css", "~/Content/css")
@Scripts.Render("~/bundles/modernizr")
<link type="text/css" href="~/Scripts/css/ui-lightness/jquery-ui-1.8.22.custom.css" rel="stylesheet" />
<script type="text/javascript" src="@Url.Content("~/Scripts/js/jquery-1.7.2.min.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/js/jquery-ui-1.8.22.custom.min.js")"></script>
</head>
<body>
<header>
<div class="content-wrapper">
<div class="float-left">
<p class="site-title">@Html.ActionLink("Your logo here", "Index", "Home")</p>
</div>
<div class="float-right">
<section id="login">
@Html.Partial("_LoginPartial")
</section>
<nav>
<ul id="menu">
<li>@Html.ActionLink(Resources.mainPage , "Index", "Home")</li>
<li>@Html.ActionLink(Resources.aboutPage, "About", "Home")</li>
<li>@Html.ActionLink(Resources.productsPage, "Index", "Home")</li>
<li>@Html.ActionLink(Resources.capabilitiesPage, "Index", "Home")</li>
<li>@Html.ActionLink(Resources.newsPage, "About", "Home")</li>
<li>@Html.ActionLink(Resources.partnersPage, "Index", "Home")</li>
</ul>
</nav>
</div>
</div>
</header>
<div id="body">
@RenderSection("featured", required: false)
<section class="content-wrapper main-content clear-fix">
@RenderBody()
</section>
</div>
<footer>
<div class="content-wrapper" >
<table >
<tr style="font-size:20px;font-weight:500;">
<td>@Html.ActionLink("О компании", "About", "Home")</td>
<td>@Html.ActionLink("О продукции", "About", "Home")</td>
<td>@Html.ActionLink("Возможности", "About", "Home")</td>
<td>@Html.ActionLink("Новости", "About", "Home")</td>
<td>@Html.ActionLink("О продукции", "About", "Home")</td>
</tr>
<tr style="font-size:12px;font-weight:500;">
<td>@Html.ActionLink("О компании", "About", "Home")</td>
<td>@Html.ActionLink("О продукции", "About", "Home")</td>
<td>@Html.ActionLink("Возможности", "About", "Home")</td>
<td>@Html.ActionLink("Новости", "About", "Home")</td>
<td>@Html.ActionLink("О продукции", "About", "Home")</td>
</tr>
<tr style="font-size:12px;font-weight:500;">
<td>@Html.ActionLink("О компании", "About", "Home")</td>
<td>@Html.ActionLink("О продукции", "About", "Home")</td>
<td>@Html.ActionLink("Возможности", "About", "Home")</td>
<td>@Html.ActionLink("Новости", "About", "Home")</td>
<td>@Html.ActionLink("О продукции", "About", "Home")</td>
</tr>
<tr style="font-size:12px;font-weight:500;">
<td>@Html.ActionLink("О компании", "About", "Home")</td>
<td>@Html.ActionLink("О продукции", "About", "Home")</td>
<td>@Html.ActionLink("Возможности", "About", "Home")</td>
<td>@Html.ActionLink("Новости", "About", "Home")</td>
<td>@Html.ActionLink("О продукции", "About", "Home")</td>
</tr>
<tr style="font-size:12px;font-weight:500;">
<td>@Html.ActionLink("О компании", "About", "Home")</td>
<td>@Html.ActionLink("О продукции", "About", "Home")</td>
<td>@Html.ActionLink("Возможности", "About", "Home")</td>
<td>@Html.ActionLink("Новости", "About", "Home")</td>
<td>@Html.ActionLink("О продукции", "About", "Home")</td>
</tr>
<tr style="font-size:12px;font-weight:500;">
<td>@Html.ActionLink("О компании", "About", "Home")</td>
<td>@Html.ActionLink("О продукции", "About", "Home")</td>
<td>@Html.ActionLink("Возможности", "About", "Home")</td>
<td>@Html.ActionLink("Новости", "About", "Home")</td>
<td>@Html.ActionLink("О продукции", "About", "Home")</td>
</tr>
<tr style="font-size:12px;font-weight:500;">
<td>@Html.ActionLink("О компании", "About", "Home")</td>
<td>@Html.ActionLink("О продукции", "About", "Home")</td>
<td>@Html.ActionLink("Возможности", "About", "Home")</td>
<td>@Html.ActionLink("Новости", "About", "Home")</td>
<td>@Html.ActionLink("О продукции", "About", "Home")</td>
</tr>
</table>
<div class="float-left">
<p>© @DateTime.Now.Year - ONM Web studio</p>
</div>
<div class="float-right">
<ul id="social">
<li><a href="http://facebook.com" class="facebook">Facebook</a></li>
<li><a href="http://twitter.com" class="twitter">Twitter</a></li>
</ul>
</div>
</div>
</footer>
@Scripts.Render("~/bundles/jquery")
@RenderSection("scripts", required: false)
</body>
</html>
index.cshtml代码
@model IEnumerable<kazwaySite.Models.News>
<script type="text/javascript">
$(function () {
$("#accordion").accordion({ header: "h3" });
});
</script>
<div id="accordion">
<div>
<h3><a href="#">First</a></h3>
<div>Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.</div>
</div>
<div>
<h3><a href="#">Second</a></h3>
<div>Phasellus mattis tincidunt nibh.</div>
</div>
<div>
<h3><a href="#">Third</a></h3>
<div>Nam dui erat, auctor a, dignissim quis.</div>
</div>
</div>
答案 0 :(得分:2)
如果未定义函数 accordion ,则不加载jquery ui。检查浏览器,该链接指向正确的位置。
答案 1 :(得分:1)
你的javascript包含完全搞乱了。您已多次包含jquery(一次在头部,一次在底部),您没有覆盖在视图中的Layout中定义的脚本部分,...
让我们试着清理一下。由于这是一个ASP.NET MVC 4应用程序,我建议你使用bundle。开箱即用的包含很多,但是jquery
有一个,jqueryui
有一个。那两个就足够了。您不需要单独包含捆绑包和脚本。这完全违背了捆绑包的目的,你经常最终得到欺骗脚本,...所以继续你的~/App_Start/BundleConfig.cs
文件并定义你想要使用的捆绑包。如果要使用更新版本的脚本,请更新NuGets。在一天结束时,您应该在~/Scripts
文件夹中拥有所需的脚本,并为它们配置捆绑ID。
@using kazwaySite
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>@ViewBag.Title - My ASP.NET MVC Application</title>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta name="viewport" content="width=device-width"
@Styles.Render("~/Content/themes/base/css", "~/Content/css")
<link type="text/css" href="~/Scripts/css/ui-lightness/jquery-ui-1.8.22.custom.css" rel="stylesheet" />
</head>
<body>
... some markup ommited for clarity ...
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryui")
@RenderSection("scripts", required: false)
</body>
</html>
并在您的视图中:
@model IEnumerable<kazwaySite.Models.News>
@section scripts {
<script type="text/javascript">
$("#accordion").accordion({ header: "h3" });
</script>
}
<div id="accordion">
<div>
<h3><a href="#">First</a></h3>
<div>Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.</div>
</div>
<div>
<h3><a href="#">Second</a></h3>
<div>Phasellus mattis tincidunt nibh.</div>
</div>
<div>
<h3><a href="#">Third</a></h3>
<div>Nam dui erat, auctor a, dignissim quis.</div>
</div>
</div>