【问题标题】:Chosen/Select2 jQuery Plugins Aren't Working With IE10Chosen/Select2 jQuery 插件不适用于 IE10
【发布时间】:2013-04-14 05:52:59
【问题描述】:

以下针对 ASP.NET MVC 4 的代码在 Firefox 和 Chrome 上正常工作(页面加载没有错误,下拉菜单显示/响应正确),但是 IE10 在页面加载时抛出以下内容:

> 0x800a01b6 - JavaScript 运行时错误:对象不支持“选择”的属性或方法

这是 SELECT html 标记:

<select class="chzn-select" data-placeholder="Group" name="Group">
    @foreach(var group in @Model.Groups)
    {
      <option value="@group">@group</option>
    }
</select>

以及它下面的 JavaScript:

 <script type="text/javascript">
    $(function () {
        $(".chzn-select").chosen();
    });
</script>

我已将 selected.css 和 selected.*.js 文件添加到适当的样式和脚本包中,然后将它们包含在我的母版页中。

(页面请求上的开发工具屏幕)

另外,我尝试了 select2,它在 IE 中遇到了同样的错误,其他浏览器运行正常。 (我更新了捆绑包以包含对 .css 和 .js 的引用)我更改的代码是:

<select class="GroupDropdown" name="Group">
      @foreach(var group in @Model.Groups)
      {
         <option value="@group">@group</option>
      }
 </select>
 <script type="text/javascript">
      $(function () {
           $(".GroupDropdown").select2();
      });
 </script>

以下适用于所有浏览器(文件位于根目录并正确命名)

<!DOCTYPE html>
<html>
<head>
    <title>Dropdown Test</title>
    <script src="jquery.js" type="text/javascript"></script>
    <script src="select2.js" type="text/javascript"></script>
    <link href="select2.css" rel="stylesheet" />
</head>
<body>
    <select>
        <option value="A">A</option>
        <option value="B">B</option>
        <option value="C">C</option>
    </select>
</body>
<script type="text/javascript">
    $(function(){
        $("select").select2();
    });
</script>
</html>

【问题讨论】:

  • 你确定脚本真的被加载了吗?
  • 你指的是哪个脚本?如果是问题中的那个,我该如何检查? (选择的.js、.css和jQuery都是根据IE10开发工具下载的)
  • 我的意思是选择的 .js。但这不是问题
  • 尝试使用更高版本的 1.8.1 而不是 1.9.1 更改您的 jquery.js。
  • 非常感谢!我添加了对 jQuery 1.8.3 的引用来代替 1.9.1,它现在可以工作了。你知道这背后的原因吗?

标签: jquery asp.net-mvc jquery-plugins internet-explorer-10


【解决方案1】:

我最近遇到了同样的问题,请确保您使用的是 1.8.1 之后的稳定 jquery 版本

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-09
    • 1970-01-01
    • 2020-10-28
    • 2020-01-02
    • 2014-11-14
    相关资源
    最近更新 更多