最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Bootstrap Switch fn is not a function - Stack Overflow

programmeradmin0浏览0评论

I'm trying to add bootstrap switch to a rails project. When I add my script from here as this:

<script src=".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.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?

Thanks!

I also tried using the bootstrap-switch gem but that was giving me a different error.

I'm trying to add bootstrap switch to a rails project. When I add my script from here as this:

<script src="https://cdnjs.cloudflare./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.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?

Thanks!

I also tried using the bootstrap-switch gem but that was giving me a different error.

Share Improve this question asked Mar 19, 2017 at 0:15 Tom HammondTom Hammond 6,09012 gold badges55 silver badges100 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

Most mon reason behind this type of error is, not having JQuery loaded before this plugin script. Make sure you have added that CDN version of bootstrap-switch.js after the JQuery.

I mean like following:

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

评论列表(0)

  1. 暂无评论