在 JavaScript 中了解 Bootstrap 3 已添加到页面上的最佳跨浏览器方式是什么?
最佳答案
一种可能的方法是简单地检查您正在使用的各种 Bootstrap 插件是否存在。例如:
if(typeof $.fn.modal === 'function') {
//it's on the page
}
所有 jQuery 插件都添加到 jQuery 原型(prototype)中,并且可以在 jQuery.fn
属性上检查它们的存在。请参阅How can I check if a jQuery plugin is loaded?
更简单地说,你可以这样做:
if($.fn.modal) {
//it's on the page
}
查看 Bootstrap 的 JS 源代码,它似乎没有删除任何您可以检查的全局变量。
关于javascript - 如何知道脚本中是否添加了 Bootstrap 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30449242/