Javascript 如何确定和打印jQuery版本?

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

How to determine and print jQuery version?

javascriptjquery

提问by James McMahon

Is there a jQuery function that returns the version of jQuery that is currently loaded?

是否有一个 jQuery 函数可以返回当前加载的 jQuery 版本?

回答by Nick Craver

You can use this:

你可以使用这个:

$.fn.jquery
//or if you're using .noConflict():
jQuery.fn.jquery

It's updated automatically when jQuery is built, defined here: http://github.com/jquery/jquery/blob/master/src/core.js#L174

它在构建 jQuery 时自动更新,定义如下:http: //github.com/jquery/jquery/blob/master/src/core.js#L174

Make sure to use $.fn.propertyfor properties that don't depend on an object, no reason to create an unneeded jquery object with $().propertyunless you intend to use it :)

确保$.fn.property用于不依赖于对象的属性,$().property除非您打算使用它,否则没有理由创建不需要的 jquery 对象:)

回答by meder omuraliev

alert( $.fn.jquery )

回答by user113716

I'm not sure how many versions of jQuery this exists in, but a jQuery object has a jqueryproperty that stores the version.

我不确定它存在于多少个 jQuery 版本中,但是 jQuery 对象有一个jquery存储版本的属性。

alert( $().jquery );

Will alert 1.4.2if you're using that version.

1.4.2如果您使用的是该版本,则会发出警报。

回答by Josiah

$().jquery;

This will return a string containing the jQuery version

这将返回一个包含 jQuery 版本的字符串

回答by Gabriele Petrioli

try

尝试

alert($().jquery)

回答by iewebguy

Alert is good, but if you want to actually print the jquery version...

警报很好,但是如果您想实际打印 jquery 版本...

<script>
document.write($.fn.jquery);
</script>