admin管理员组文章数量:1356738
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 badges1 Answer
Reset to default 6Most 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>
本文标签: javascriptBootstrap Switch fn is not a functionStack Overflow
版权声明:本文标题:javascript - Bootstrap Switch fn is not a function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743987251a2571492.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论