Javascript 通过检查 jQuery 对象获取 jQuery 版本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6867040/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 23:32:44  来源:igfitidea点击:

Get jQuery version from inspecting the jQuery object

javascriptjquery

提问by Jeff

Is there a way to find out what version of jQuery is being used by inspecting the jQueryobject? jQuery is dynamically getting added to my page and I cannot see any reference to it in my markup. If I inspect it in my browser's console, it's there.

有没有办法通过检查jQuery对象来找出正在使用的 jQuery 版本?jQuery 正在动态添加到我的页面中,但我在标记中看不到任何对它的引用。如果我在浏览器的控制台中检查它,它就在那里。

回答by David Hancock

You can use either $().jquery;or $.fn.jquerywhich will return a string containing the version number, e.g. 1.6.2.

您可以使用$().jquery;or$.fn.jquery返回包含版本号的字符串,例如1.6.2.

回答by Devy

FYI, for the cases where your page is loading with other javascript libraries like mootools that are conflicting with the $symbol, you can use jQueryinstead.

仅供参考,对于您的页面正在加载与$符号冲突的其他 javascript 库(如 mootools)的情况,您可以jQuery改用。

For instance, jQuery.fn.jqueryor jQuery().jquerywould work just fine:

例如,jQuery.fn.jquery或者jQuery().jquery可以正常工作:

screen shot for checking jQuery version

检查 jQuery 版本的屏幕截图

回答by Abdennour TOUMI

$()['jquery']

Invoke console.log($())and take note about jquery object fields :

调用console.log($())并注意 jquery 对象字段:

  • jquery
  • selector
  • prevObject
  • 查询
  • 选择器
  • 上一个对象

enter image description here

在此处输入图片说明

回答by ShankarSangoli

$().jquerywill give you its version as a string.

$().jquery会给你它的版本作为一个字符串。

回答by Lead Developer

For older versions of jQuery

对于旧版本的 jQuery

jQuery().jquery  (or)

jQuery().fn.jquery

For newer versions of jQuery

对于较新版本的 jQuery

$().jquery  (or)

$().fn.jquery

回答by Arun Kumar

You can get the version of the jquery by simply printing object.jquery, the objectcan be any object created by you using $.

您可以通过简单的打印来获取 jquery 的版本object.jquery,它object可以是您使用$.

For example: if you have created a <div>element as following

例如:如果您创建了一个<div>元素如下

var divObj = $("div");

then by printing divObj.jquerywill show you the version like 1.7.1

然后通过打印divObj.jquery将显示像 1.7.1 这样的版本

Basically divObjinherits all the property of $()or jQuery()i.e if you try to print jQuery.fn.jquerywill also print the same version like 1.7.1

基本上divObj继承了$()or 的所有属性,jQuery()即如果您尝试打印jQuery.fn.jquery也会打印与 1.7.1 相同的版本

回答by Lakshmana Kumar D

console.log( 'You are running jQuery version: ' + $.fn.jquery );