本文翻译自:Get jQuery version from inspecting the jQuery object
Is there a way to find out what version of jQuery is being used by inspecting the jQuery
object? 有没有办法通过检查jQuery
对象找出正在使用的jQuery版本? jQuery is dynamically getting added to my page and I cannot see any reference to it in my markup. jQuery动态地添加到我的页面,我在我的标记中看不到任何对它的引用。 If I inspect it in my browser's console, it's there. 如果我在浏览器的控制台中检查它,它就在那里。
#1楼
参考:https://stackoom.com/question/SoQi/从检查jQuery对象获取jQuery版本
#2楼
FYI, for the cases where your page is loading with other javascript libraries like mootools that are conflicting with the $
symbol, you can use jQuery
instead. 仅供参考,对于您的页面加载其他javascript库(例如与$
符号冲突的mootools)的情况,您可以使用jQuery
代替。
For instance, jQuery.fn.jquery
or jQuery().jquery
would work just fine: 例如, jQuery.fn.jquery
或jQuery().jquery
可以正常工作:
#3楼
$()['jquery']
Invoke console.log($())
and take note about jquery object fields : 调用console.log($())
并记下jquery对象字段:
- jquery jQuery的
- selector 选择
- prevObject prevObject
#4楼
console.log( 'You are running jQuery version: ' + $.fn.jquery );
#5楼
For older versions of jQuery 对于旧版本的jQuery
jQuery().jquery (or)
jQuery().fn.jquery
For newer versions of jQuery 对于较新版本的jQuery
$().jquery (or)
$().fn.jquery
#6楼
You can use either $().jquery;
你可以使用$().jquery;
or $.fn.jquery
which will return a string containing the version number, eg 1.6.2
. 或$.fn.jquery
将返回包含版本号的字符串,例如1.6.2
。