检测jquery和lodash版本
/**
* 获取前端库版本信息
*/
function getLibraryVersions() {
const versions = {
jquery: null,
lodash: null
};
// 1. 获取 jQuery 版本
// jQuery 将版本号存储在 jQuery.fn.jquery 或 $.fn.jquery 中
if (typeof jQuery !== 'undefined' && jQuery.fn && jQuery.fn.jquery) {
versions.jquery = jQuery.fn.jquery;
} else if (typeof $ !== 'undefined' && $.fn && $.fn.jquery) {
// 兼容使用 $ 别名的情况
versions.jquery = $.fn.jquery;
}
// 2. 获取 Lodash 版本
// Lodash 将版本号存储在 _.VERSION 中
if (typeof _ !== 'undefined' && _.VERSION) {
versions.lodash = _.VERSION;
}
// 某些打包环境可能将 lodash 挂载在其他变量上,如有需要可在此扩展
return versions;
}
// 执行检测并输出结果
const libVersions = getLibraryVersions();
console.log("=== 库版本检测结果 ===");
if (libVersions.jquery) {
console.log(`jQuery 版本: ${libVersions.jquery}`);
} else {
console.warn("当前页面未检测到 jQuery");
}
if (libVersions.lodash) {
console.log(`Lodash 版本: ${libVersions.lodash}`);
} else {
console.warn("当前页面未检测到 Lodash");
}
浙公网安备 33010602011771号