【问题标题】:Bootstrap Switch fn is not a functionBootstrap Switch fn 不是函数
【发布时间】:2017-08-10 10:08:16
【问题描述】:

我正在尝试将引导开关添加到 rails 项目。当我从here 添加我的脚本时:

<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-switch/3.3.4/js/bootstrap-switch.js" data-turbolinks-track="true"></script>

我最终在控制台中收到错误:

Uncaught TypeError: Cannot read property 'fn' of undefined
    at bootstrap-switch.js:743
    at bootstrap-switch.js:19
    at bootstrap-switch.js:22

此处以红色突出显示为问题的 fn:

$.fn.bootstrapSwitch = function (option) {
    for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
      args[_key2 - 1] = arguments[_key2];
    }

任何想法为什么找不到?或者有人有我可以使用的 bootstrap-switch.js 文件的链接吗?

谢谢!

我也尝试使用bootstrap-switch gem,但这给了我一个不同的错误。

【问题讨论】:

    标签: javascript ruby-on-rails twitter-bootstrap angular-ui-bootstrap bootstrap-switch


    【解决方案1】:

    此类错误背后的最常见原因是,在此插件脚本之前没有加载 JQuery。确保在 JQuery 之后添加了 bootstrap-switch.js 的 CDN 版本。

    我的意思如下:

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-switch/3.3.4/js/bootstrap-switch.js" data-turbolinks-track="true"></script>
    

    【讨论】:

    • 在此之后最终拉入了我的 Rails javascript……令人尴尬。很好的收获。
    猜你喜欢
    • 2020-08-23
    • 2020-09-23
    • 2016-10-21
    • 2020-11-04
    • 2021-01-26
    • 1970-01-01
    • 2016-11-30
    • 2015-10-20
    • 2014-06-29
    相关资源
    最近更新 更多