jquery slider Uncaught TypeError:undefined不是函数

时间:2014-09-10 22:13:55

标签: javascript jquery jquery-ui asp.net-mvc-4 uislider

使用jQuery .slider()遇到问题。我使用从here下载的最新版本的jQuery(使用该下载中的UI和jQuery库)。

当页面加载试图将滑块绑定到div的行时,会收到以下错误

enter image description here

_Layout.cshtml

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>@ViewBag.Title</title>
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/jqueryui")
    @Scripts.Render("~/bundles/jsMVC")
    @Scripts.Render("~/bundles/BackboneApps")
</head>

BundleCollections

        bundles.Add(new ScriptBundle("~/bundles/BackboneApps").Include(
                    "~/Scripts/SliderApp.js"));
        bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                    "~/Scripts/jquery.js"));
        bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
                    "~/Scripts/jquery-ui.js"));
        bundles.Add(new ScriptBundle("~/bundles/jsMVC").Include(
                    "~/Scripts/underscore.js",
                    "~/Scripts/backbone.js"));

呈现HTML

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title></title>
    <link href="/Content/site.css" rel="stylesheet"/>
    <script src="/Scripts/jquery.js"></script>
    <script src="/Scripts/jquery-ui.js"></script>
    <script src="/Scripts/underscore.js"></script>
    <script src="/Scripts/backbone.js"></script>
    <script src="/Scripts/SliderApp.js"></script>
</head>

SliderApp.js

    $(document).ready(function () {
        // Initialize jquery slider
        $("#slider").slider();
        .
        .
    });

Index.cshtml

    <!-- "slider" is a jquery slider -->
    <div id="slider"></div>

    <!-- "sliderVal" displays the slider's position. It receives the value via model. -->
    <input type="text" id="sliderVal" value="0"/>

1 个答案:

答案 0 :(得分:2)

发生了这种情况,因为在页面底部是随机的

@Scripts.Render("~/bundles/jquery")

进入了。由于jQuery库加载了两次,上面的ui被吹走了。