我如何获得 jQuery-UI 版本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3657953/
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 do I get the jQuery-UI version?
提问by Brock Adams
This should be an easy question, but how do I detect the jQuery-UI version?
这应该是一个简单的问题,但是如何检测 jQuery-UI 版本?
This is for a Greasemonkey script and the (current) target page appears to be running jQuery-UI, 1.5.2. But, different target pages may run different versions.
这是针对 Greasemonkey 脚本的,(当前)目标页面似乎正在运行 jQuery-UI,1.5.2。但是,不同的目标页面可能运行不同的版本。
console.log ($.ui);
did not show anything useful/obvious for version detection.
console.log ($.ui);
没有显示任何有用/明显的版本检测。
回答by Nick Craver
You can use $.ui.version
, it's actually the property jQuery UI looks for when determining if it should load itself (if it's already there, abort).
您可以使用$.ui.version
,它实际上是 jQuery UI 在确定是否应该加载自身时查找的属性(如果它已经存在,则中止)。
For example here's a fiddle including version 1.8.4.
Unfortunately, $.ui.version
was added in jQuery-UI version 1.6.
不幸的是,它$.ui.version
是在 jQuery-UI 1.6 版中添加的。
For earlier versions, you can check for $.ui
though.
对于早期版本,您可以检查一下$.ui
。
So, in this case, the following might be good enough:
因此,在这种情况下,以下内容可能就足够了:
var version = $.ui ? $.ui.version || "pre 1.6" : 'jQuery-UI not detected';