【问题标题】:0x800a138f - JavaScript runtime error: Unable to get property 'fn' of undefined or null reference0x800a138f - JavaScript 运行时错误:无法获取未定义或空引用的属性“fn”
【发布时间】:2016-03-30 06:20:51
【问题描述】:

我正在尝试做这个例子http://jsfiddle.net/pmrotule/w7aakdbb/54/

我得到了这个异常

0x800a138f - JavaScript 运行时错误:无法获取未定义或空引用的属性“fn”。 和 0x800a01b6 - JavaScript 运行时错误:对象不支持属性或方法“多选”。 此时它在 bootstarp-multiselect.js 中抛出错误

$.fn.multiselect = function(option, parameter, extraOptions) {
    return this.each(function() {
        var data = $(this).data('multiselect');
        var options = typeof option === 'object' && option;

        // Initialize the multiselect.
        if (!data) {
            data = new Multiselect(this, options);
            $(this).data('multiselect', data);
        }

        // Call multiselect method.
        if (typeof option === 'string') {
            data[option](parameter, extraOptions);

            if (option === 'destroy') {
                $(this).data('multiselect', false);
            }
        }
    });
};

我的 HTML 代码:

<script src="~/Scripts/bootstrap-multiselect.js"></script>
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<link href="~/Content/bootstrap-multiselect.css" rel="stylesheet" />
<script src="~/Scripts/bootstrap.js"></script>
<select id="ddlCars" multiple="multiple">
   <option value="Accord">Accord</option>
   <option value="Duster">Duster</option>
   <option value="Esteem">Esteem</option>
   <option value="Fiero">Fiero</option>
</select>
<script>
   $('#ddlCars').multiselect();
</script>

我在 VS2013 中使用 ASP.NET MVC 项目。 我得到了这个例外 我对 JS 和 BootStarp 很陌生。

【问题讨论】:

  • jquery.js 必须是第一个(bootstrap-multiselect.js) 之前
  • 谢谢。它有帮助。

标签: javascript asp.net-mvc twitter-bootstrap-3 multi-select


【解决方案1】:

更正脚本顺序,jQuery js 应该是第一个加载的,因为bootstrap.jsbootstrap-multiselect.js 依赖于jquery js

<link href="~/Content/bootstrap-multiselect.css" rel="stylesheet" />
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/bootstrap.js"></script>
<script src="~/Scripts/bootstrap-multiselect.js"></script>

【讨论】:

  • 谢谢。它解决了我的第一个问题。现在我收到错误 0x800a01b6 - JavaScript 运行时错误:对象不支持属性或方法“多选”。
  • @JyotirmayaPrusty..如果可能,请创建一个描述您的问题的小提琴,以便我们调试和更正代码。
  • 这是我正在研究的小提琴jsfiddle.net/iminfo/txnot4h1。在小提琴中工作正常,但我在 VS13 中遇到此错误
【解决方案2】:

错误的意思是 $ 尚未定义(在执行 bootstarp-multiselect.js 期间),因为您需要先加载 jQuery。

由于bootstrap-multiselect.js 可以依赖于引导程序,所以在bootstrap-multiselect.js 之前加载bootstrap.js 也没有什么坏处。

所以:

<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/bootstrap.js"></script>
<script src="~/Scripts/bootstrap-multiselect.js"></script>
...

【讨论】:

  • 谢谢。它解决了我的第一个问题。现在我收到错误 0x800a01b6 - JavaScript 运行时错误:对象不支持属性或方法“多选”。
  • 尝试在文档就绪而不是直接执行您的代码:$(function() { $('#ddlCars').multiselect(); });,参见api.jquery.com/ready
  • 我现在正在做这个小提琴:jsfiddle.net/iminfo/txnot4h1 这在小提琴中工作正常,但在 VS13 中抛出上述错误。
【解决方案3】:

javascript 文件包含顺序错误,应先包含 jQuery 文件。

【讨论】:

    猜你喜欢
    • 2015-07-07
    • 2014-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多