如何检查页面上是否加载了 bootstrap.js
文件(bootstrap.js
文件本身可能会被编译/缩小为另一个更大的 JS文件)?
How can I check whether there is a bootstrap.js
file loaded on a page (the bootstrap.js
file itself may be compiled/minified into another, bigger JS file)?
您需要做的只是检查 Bootstrap 特定的方法是否可用.我将在此示例中使用模态(适用于 Bootstrap 2-4):
All you need to do is simply check if a Bootstrap-specific method is available. I'll use modal in this example (works for Bootstrap 2-4):
// Will be true if bootstrap is loaded, false otherwise
var bootstrap_enabled = (typeof $().modal == 'function');
它显然不是 100% 可靠的,因为模态函数可以由不同的插件提供,但它仍然可以完成这项工作......
It is not 100% reliable obviously since a modal function can be provided by a different plugin, but nonetheless it will do the job...
您还可以更具体地检查 Bootstrap 3-4(从 3.1+ 开始工作):
You can also check for Bootstrap 3-4 more specifically (works as of 3.1+):
// Will be true if Bootstrap 3-4 is loaded, false if Bootstrap 2 or no Bootstrap
var bootstrap_enabled = (typeof $().emulateTransitionEnd == 'function');
请注意,所有这些检查都要求 jQuery 已加载.
Note that all of these checks require that jQuery is already loaded.
这篇关于如何检查 Twitter 引导程序是否已加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!