繁体   English   中英

('...')。对于带有jquery包的asp.net核心mvc,每个都不是有效函数

[英]('…').each not a valid function for asp.net core mvc with jquery bundle

重新发布此内容是因为我找不到任何不涉及使用Google捆绑软件或其他工具的答案。 请告诉我是否缺少任何细节,所以我将其添加。 我在_Layout的顶部引用了VS随附的整个jquery包...

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

这是BundleConfig.cs

public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                        "~/Scripts/jquery-{version}.js"));

            bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                        "~/Scripts/jquery.validate*"));

            // Use the development version of Modernizr to develop with and learn from. Then, when you're
            // ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
            bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                        "~/Scripts/modernizr-*"));

            bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                      "~/Scripts/bootstrap.js",
                      "~/Scripts/respond.js"));

            bundles.Add(new StyleBundle("~/Content/css").Include(
                      "~/Content/bootstrap.css",
                      "~/Content/site.css"));
        }

...但是在这种情况下,它仍然告诉我.each不是函数。 我所缺少的或需要引用的布局或BundleConfig? 为什么.each不是Visual Studio 2017随附的jquery捆绑包中的一部分的函数?

@Html.ListBox("Groups", null, new { size = 10, style = "width : 350px; max-width : 500px;", id = "grouplist" })

我的jQuery的整个上下文:

    $('#savegroups').click(function () {
            var groupId = $('#groupId').val();
            var list = [];
            ('#grouplist').each(function (item) {
                list.append('{"groupId":"' + groupId + '","groupName":"' + item.value +'"}');
            });
            $.ajax({
                type: "POST",
                url: "/GroupCategories/EditGroups",
                data: JSON.stringify(list),
            });
   });

错误:

1:230 Uncaught TypeError: "#grouplist".each is not a function
    at HTMLInputElement.<anonymous> (1:230)
    at HTMLInputElement.dispatch (jquery:1)
    at HTMLInputElement.y.handle (jquery:1)

看起来您缺少jquery选择器。

('#grouplist')

应该

$('#grouplist option')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM