【问题标题】:jQuery Cycle Plugin not working in ASP.NET MVC 4jQuery 循环插件在 ASP.NET MVC 4 中不起作用
【发布时间】:2013-04-18 07:28:55
【问题描述】:

我刚刚默认创建了 ASP .NET MVC4 项目,并从this 示例中放入了一些代码,但它根本不起作用。

有什么线索吗?

错误:

未捕获的 ReferenceError:未定义 jQuery jquery.cycle.all.latest.js:918 Uncaught ReferenceError: $ is not 定义

<!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/css")
    @Scripts.Render("~/bundles/modernizr")

    <style type="text/css">
        .slideshow {
            height: 232px;
            width: 232px;
            margin: auto;
        }

            .slideshow img {
                padding: 15px;
                border: 1px solid #ccc;
                background-color: #eee;
            }
    </style>

    <script type="text/javascript" src="http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.latest.js"></script>

    <script type="text/javascript">
        $(document).ready(function () {
            $('.slideshow').cycle({
                fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
            });
        });
    </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("Home", "Index", "Home")</li>
                        <li>@Html.ActionLink("About", "About", "Home")</li>
                        <li>@Html.ActionLink("Contact", "Contact", "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">
            <div class="float-left">
                <p>&copy; @DateTime.Now.Year - My ASP.NET MVC Application</p>
            </div>
        </div>
    </footer>

</body>
</html>

【问题讨论】:

  • 错误是什么?你想要完成什么?你试过什么? ...
  • @Kenneth 请看一下这个问题,我已经更新了。谢谢!
  • 您似乎没有在任何地方包含 jQuery 库。它必须包含在 jquery.cycle 插件之前

标签: jquery asp.net-mvc-4 jquery-cycle


【解决方案1】:

您似乎没有包含 jQuery 库。您需要将此添加到您的 &lt;head&gt; 部分:

<!-- include jQuery library -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>

【讨论】:

  • 问题:包含 ASP .NET MVC4 jQuery 吗?嗯
  • 大部分MVC4项目模板都应该默认有它。
  • @jmoerdyk 没错!所以我用了MS提供的那个。
  • 但是您没有将它包含在页面中。如果您的项目有它,请尝试在包含插件之前在该行添加@Scripts.Render("~/bundles/jquery")
  • Bundles.Config 中的所有行都是 define 包,要使用该包中的脚本,您仍然需要将该包呈现到页面。跨度>
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-07-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多