繁体   English   中英

Bootstrap Switch fn不起作用

[英]Bootstrap Switch fn is not a function

我正在尝试将引导程序开关添加到Rails项目。 当我从此处添加脚本时,如下所示:

<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,但这给了我一个不同的错误。

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

我的意思是如下:

<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>

暂无
暂无

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

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