如何检查客户端机器上加载了jQuery的哪个版本?客户端可能有jQuery加载,但我不知道如何检查它。如果他们有加载,我如何检查版本和前缀,如:

$('.class')
JQuery('.class')

当前回答

使用可选的链接操作符(?.),这可以用window.jQuery?.fn?.jquery完成。如果根本没有加载jQuery,这一行也可以工作。

其他回答

也许不言自明,但我发现的最简单的方法是查看实际文件中注释的版本(通常是jquery.min.js)。或者,如果使用类似code.jquery.com的东西,则版本号在https引用中(即https://code.jquery.com/jquery-1.11.3.js)。

在这里输入图像描述

根据模板怪物博客,键入,这些下面的脚本将给你的网站jquery的版本,你现在正在遍历。

 1. console.log(jQuery.fn.jquery);
 2. console.log(jQuery().jquery);
if (typeof jQuery != 'undefined') {  
    // jQuery is loaded => print the version
    alert(jQuery.fn.jquery);
}

在一行和最少的按键(哎呀!):

alert($().jquery);

只是因为这个方法到目前为止还没有提到-打开控制台并键入:

$ === jQuery

正如@Juhana上面提到的$()。Jquery将返回版本号。