twitter-bootstrap 如何通过 javascript 获取引导程序版本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43233588/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I get bootstrap version via javascript?
提问by Selman Gen?
Is there any way to get bootstrapversion via calling a function? I did some research but couldn't find any way, the version information is included in the comments at the beginning like this:
有没有办法bootstrap通过调用函数来获取版本?我做了一些研究但找不到任何方法,版本信息包含在开头的评论中,如下所示:
/*!
* Bootstrap v3.3.7 (http://getbootstrap.com)
* Copyright 2011-2016 Twitter, Inc.
* Licensed under the MIT license
*/
/*!
* Bootstrap v3.3.7 (http://getbootstrap.com)
* Copyright 2011-2016 Twitter, Inc.
* Licensed under the MIT license
*/
But in case the comments are removed how do I get the bootstrap version? Bootstrap plugins have a version defined in them but I'm looking for the general bootstrap version, not version of a particular plugin.
但如果评论被删除,我该如何获得引导程序版本?Bootstrap 插件中定义了一个版本,但我正在寻找通用的引导程序版本,而不是特定插件的版本。
回答by roberto tomás
The version of each of Bootstrap's jQuery plugins can be accessed via the VERSION property of the plugin's constructor. For example, for the tooltip plugin:
可以通过插件构造函数的 VERSION 属性访问每个 Bootstrap jQuery 插件的版本。例如,对于工具提示插件:
$.fn.tooltip.Constructor.VERSION // => "3.3.7"
src //getbootstrap.com/javascript/#js-version-nums
src //getbootstrap.com/javascript/#js-version-nums
if you mean from the css, then yu ahve to AJAX the file and .match(/v[.\d]+[.\d]/);
如果你的意思是从 css 中,那么你 ahve 到 AJAX 文件和 .match(/v[.\d]+[.\d]/);
回答by Nico_
You can use this code found here:
您可以使用此处找到的代码:
var getBootstrapVersion = function () {
var deferred = $.Deferred();
var script = $('script[src*="bootstrap"]');
if (script.length == 0) {
return deferred.reject();
}
var src = script.attr('src');
$.get(src).done(function(response) {
var matches = response.match(/(?!v)([.\d]+[.\d])/);
if (matches && matches.length > 0) {
version = matches[0];
deferred.resolve(version);
}
});
return deferred;
};
getBootstrapVersion().done(function(version) {
console.log(version); // '3.3.4'
});
回答by callaginn
This spinoff of the Constructor method adds a fallback plugin and returns an array:
这个 Constructor 方法的衍生添加了一个回退插件并返回一个数组:
var version = ($().modal||$().tab).Constructor.VERSION.split('.');
You can access the major revision with version[0], of course.
version[0]当然,您可以使用 访问主要修订版。
回答by VnDevil
you can find bootstrap version here: https://getbootstrap.com/docs/4.3/getting-started/javascript/#version-numbers
你可以在这里找到引导程序版本:https: //getbootstrap.com/docs/4.3/getting-started/javascript/#version-numbers
$.fn.tooltip.Constructor.VERSION // => "4.3.1"

