如何检查是否加载了Twitter引导程序? [英] How to check if Twitter bootstrap is loaded?

查看:126
本文介绍了如何检查是否加载了Twitter引导程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查页面上是否加载了bootstrap.js(文件bootstrap.js可能被编译成另一个大型JS文件)?

How can I check whether there is a bootstrap.js loaded on page (a file bootstrap.js may be compiled into another big JS file)?

推荐答案

您只需检查特定于Bootstrap的方法是否可用。我将在此示例中使用modal(适用于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引导程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆