如何检查客户端机器上加载了jQuery的哪个版本?客户端可能有jQuery加载,但我不知道如何检查它。如果他们有加载,我如何检查版本和前缀,如:
$('.class')
JQuery('.class')
如何检查客户端机器上加载了jQuery的哪个版本?客户端可能有jQuery加载,但我不知道如何检查它。如果他们有加载,我如何检查版本和前缀,如:
$('.class')
JQuery('.class')
当前回答
转到开发人员工具>控制台,并编写以下命令之一 jQuery.fn.jquery console.log (jQuery () .jquery);
其他回答
我发现这是检查jQuery是否加载的最短和最简单的方法:
if (window.jQuery) {
// jQuery is available.
// Print the jQuery version, e.g. "1.0.0":
console.log(window.jQuery.fn.jquery);
}
http://html5boilerplate.com和其他公司使用了这种方法。
你应该在IE的try/catch块中封装这个:
// Ensure jquery is loaded -- syntaxed for IE compatibility
try
{
var jqueryIsLoaded=jQuery;
jQueryIsLoaded=true;
}
catch(err)
{
var jQueryIsLoaded=false;
}
if(jQueryIsLoaded)
{
$(function(){
/** site level jquery code here **/
});
}
else
{
// Jquery not loaded
}
也许不言自明,但我发现的最简单的方法是查看实际文件中注释的版本(通常是jquery.min.js)。或者,如果使用类似code.jquery.com的东西,则版本号在https引用中(即https://code.jquery.com/jquery-1.11.3.js)。
在这里输入图像描述
只是因为这个方法到目前为止还没有提到-打开控制台并键入:
$ === jQuery
正如@Juhana上面提到的$()。Jquery将返回版本号。
转到开发人员工具>控制台,并编写以下命令之一 jQuery.fn.jquery console.log (jQuery () .jquery);