简体   繁体   English

Bootstrap Switch fn不起作用

[英]Bootstrap Switch fn is not a function

I'm trying to add bootstrap switch to a rails project. 我正在尝试将引导程序开关添加到Rails项目。 When I add my script from here as this: 当我从此处添加脚本时,如下所示:

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

I end up getting an error in the console: 我最终在控制台中得到一个错误:

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

And the fn that's highlighted red as an issue is here: 这里突出显示为红色的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];
    }

Any ideas why that isn't found? 有什么想法为什么找不到? Or does anyone have a link to a bootstrap-switch.js file that I can use that will work? 还是有人可以使用我可以使用的bootstrap-switch.js文件的链接?

Thanks! 谢谢!

I also tried using the bootstrap-switch gem but that was giving me a different error. 我也尝试使用bootstrap-switch gem,但这给了我一个不同的错误。

Most common reason behind this type of error is, not having JQuery loaded before this plugin script. 此类错误的最常见原因是,在此插件脚本之前未加载JQuery。 Make sure you have added that CDN version of bootstrap-switch.js after the JQuery. 确保在JQuery之后添加了CDN版本的bootstrap-switch.js

I mean like following: 我的意思是如下:

<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