How to check if Twitter bootstrap is loaded?(如何检查 Twitter 引导程序是否已加载?)
问题描述
如何检查页面上是否加载了 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 引导程序是否已加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何检查 Twitter 引导程序是否已加载?
基础教程推荐
- Bootstrap 模态出现在背景下 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
