【问题标题】:Importing javascript library works in chrome but not IE导入 javascript 库适用于 chrome 但不适用于 IE
【发布时间】:2015-11-26 11:54:56
【问题描述】:

我正在使用 ASP.NET MVC 5,我正在尝试将一些 javascript 库导入为 jquery、bootstrap.js 等等。它在 Chrome 中运行良好,但在 IE 11 中运行良好。

谁能看到我错过了什么?

捆绑配置:

public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                    "~/Scripts/jquery-2.1.4.js",
                    "~/Scripts/jquery-2.1.4.min.js",
                    "~/Scripts/EventReader.js",
                    "~/Scripts/jquery.floatThead.js",
                    "~/Scripts/jquery.floatThead.min.js",
                    "~/Scripts/jquery.unobtrusive-ajax.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/bootstrap.min.css",
                  "~/Content/EventReader.css"));
    }

_布局:

<!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")
@Styles.Render("~/Content/bootstrap")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")


</head>
<body>
<div class="container body-content">
@RenderBody()
@RenderSection("scripts", required: false)
</div>

</body>
</html>

还有我的视图(索引):

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

<html>
<head>
<meta name="viewport" content="width=device-width"/>
<title>Index</title>

</head>
<body>
</body>

在 IE11 中出现以下错误:

Object doesn't support property or method 'addEventListener' (jquery-2.1.4.js).
Object doesn't support property or method 'addEventListener' (jquery-2.1.4.min.js)
Bootstrap's JavaScript requires jQuery (bootstrap.js)

【问题讨论】:

  • @RenderBody() 从您的 View(Index.cshtml) 获取内容,因此无需在您的视图中声明 html、head、title、meta 和 body 标签。只需声明内容。
  • @Dandy 谢谢,但没有帮助
  • 在IE11中查看源码得到什么,在html源码中看到script标签了吗?
  • @Dandy 是的,我可以在 head 标签中看到它们。首先是jquery,Jquery.Min,unobtrusive-ajax,等等……
  • 如果您打开 IE 调试工具(按 F12),并且在“控制台”窗口中没有看到任何 javascript 错误,那么我想一切正常。

标签: javascript jquery asp.net-mvc google-chrome internet-explorer


【解决方案1】:

添加 &lt;meta http-equiv="X-UA-Compatible" content="IE=Edge"&gt; 在文档头部 强制 IE 以最新的 IE 版本的标准呈现。

【讨论】:

    猜你喜欢
    • 2017-11-22
    • 1970-01-01
    • 1970-01-01
    • 2015-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-06
    • 2014-05-17
    相关资源
    最近更新 更多