gpt4 book ai didi

javascript - 无法在我的 ASP.NET MVC 应用程序中运行任何 jQuery 插件,原因是什么?

转载 作者:行者123 更新时间:2023-12-03 07:39:43 24 4
gpt4 key购买 nike

这些天我经历了困难时期,我尝试实现一个名为 elevate Zoom 的 jQuery 插件,但没有成功,我认为这可能是 jQuery 插件的问题,并改用 Cloud Zoom,但还没有成功。我将该插件所需的所有脚本以及 CSS 都放入了我的 View 中,您可以看到我的 View 代码:

@{
ViewBag.Title = "Zoom";
Layout = "~/Views/Shared/_Layout.cshtml";
}



<title>Cloud Zoom</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<!-- Include jQuery. -->
<script type="text/javascript" src="~/Scripts/jquery-1.10.2.min.js"></script>

<!-- Include Cloud Zoom CSS. -->
<link rel="stylesheet" type="text/css" href="~/Content/cloudzoom.css" />

<!-- Include Cloud Zoom script. -->
<script type="text/javascript" src="~/Scripts/cloudzoom.js"></script>

<!-- Call quick start function. -->
<script type="text/javascript">
$(function(){CloudZoom.quickStart();})
</script>

<!-- Setup the zoomImage property to point to the big image. -->
<img class="cloudzoom" src="~/images/small/image1.jpg"
data-cloudzoom="zoomImage: '~/images/large/image1.jpg'" />

布局代码:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - My ASP.NET Application</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")

</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
@Html.ActionLink("Application name", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
</ul>
@Html.Partial("_LoginPartial")
</div>
</div>
</div>
<div class="container body-content">
@RenderBody()
<hr />
<footer>
<p>&copy; @DateTime.Now.Year - My ASP.NET Application</p>
</footer>
</div>

@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
</body>
</html>

最终生成的 HTML:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Zoom - My ASP.NET Application</title>
<link href="/Content/bootstrap.css" rel="stylesheet"/>
<link href="/Content/site.css" rel="stylesheet"/>


</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">Application name</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="/">Home</a></li>
<li><a href="/Home/About">About</a></li>
<li><a href="/Home/Contact">Contact</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="/Account/Register" id="registerLink">Register</a></li>
<li><a href="/Account/Login" id="loginLink">Log in</a></li>
</ul>

</div>
</div>
</div>
<div class="container body-content">






<title>Cloud Zoom</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<!-- Include jQuery. -->
<script type="text/javascript" src="/Scripts/jquery-1.10.2.min.js"></script>

<!-- Include Cloud Zoom CSS. -->
<link rel="stylesheet" type="text/css" href="/Content/cloudzoom.css" />

<!-- Include Cloud Zoom script. -->
<script type="text/javascript" src="/Scripts/cloudzoom.js"></script>

<!-- Call quick start function. -->
<script type="text/javascript">
$(function(){CloudZoom.quickStart();})
</script>

<!-- Setup the zoomImage property to point to the big image. -->
<img class="cloudzoom" src="/images/small/image1.jpg"
data-cloudzoom="zoomImage: '~/images/large/image1.jpg'" />





<hr />
<footer>
<p>&copy; 2016 - My ASP.NET Application</p>
</footer>
</div>

<script src="/Scripts/bootstrap.js"></script>
<script src="/Scripts/respond.js"></script>



<!-- Visual Studio Browser Link -->
<script type="application/json" id="__browserLink_initializationData">
{"appName":"Firefox","requestId":"c6cb955b8169466e9a82c8082a334502"}
</script>
<script type="text/javascript" src="http://localhost:6214/1d36907a16cf4beea1f3582a362b6719/browserLink" async="async"></script>
<!-- End Browser Link -->

</body>
</html>

最佳答案

嗯,乍一看,我发现你实际上嵌套了 <html> <body>里面标签。这是完全错误的。

另请查看这部分代码:

data-cloudzoom="zoomImage: '~/images/large/image1.jpg'"

图像 URL 未翻译,蒂尔达字符 ~停留在最终生成的 HTML 中,这是错误的。大概应该是:

<img class="cloudzoom" src="@Url.Content("~/images/small/image1.jpg")"
data-cloudzoom="zoomImage: '@Url.Content(~/images/large/image1.jpg")'" />

布局应如下所示:请注意@RenderSection来电。

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - My ASP.NET Application</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@RenderSection("stylesheets", required: false)
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
@Html.ActionLink("Application name", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
</ul>
@Html.Partial("_LoginPartial")
</div>
</div>
</div>
<div class="container body-content">
@RenderBody()
<hr />
<footer>
<p>&copy; @DateTime.Now.Year - My ASP.NET Application</p>
</footer>
</div>

@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
</body>
</html>

View 应如下所示:请注意这些部分。

@{
ViewBag.Title = "Zoom";
Layout = "~/Views/Shared/_Layout.cshtml";
}

@section stylesheets {
<!-- Include Cloud Zoom CSS. -->
<link rel="stylesheet" type="text/css" href="~/Content/cloudzoom.css" />
}

@section scripts {
<!-- Include jQuery. -->
<script type="text/javascript" src="~/Scripts/jquery-1.10.2.min.js"></script>

<!-- Include Cloud Zoom script. -->
<script type="text/javascript" src="~/Scripts/cloudzoom.js"></script>
}

<!-- Call quick start function. -->
<script type="text/javascript">
CloudZoom.quickStart();
</script>

<!-- Setup the zoomImage property to point to the big image. -->
<img class="cloudzoom" src="@Url.Content("~/images/small/image1.jpg")"
data-cloudzoom="zoomImage: '@Url.Content("~/images/large/image1.jpg")'" />

关于javascript - 无法在我的 ASP.NET MVC 应用程序中运行任何 jQuery 插件,原因是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35457902/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com