如何检测是否安装了Jquery和Jquery UI,以及安装了哪些版本?

编程入门 行业动态 更新时间:2024-10-11 19:24:09
本文介绍了如何检测是否安装了Jquery和Jquery UI,以及安装了哪些版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在JS中创建一个将从外部站点调用的脚本,但是我的代码需要Jquery才能工作,特别是1.7和1.8用于UI,我找到了一种方法来检查是否安装了jquery并获得版本:

I am creating a script in JS that will be called from external sites, but my code requires Jquery to work, specially 1.7 and 1.8 for UI, I found a way to check if jquery is installed and get the version:

$().jquery

但这会给我一个带点的字符串(1.6.1);是否已经有一个功能来检查安装的版本是否比我要求的版本旧?

But this will give me back a string with dots (1.6.1); is there already a function to check if the version installed is older than the one that I required?

我还需要相同的UI库,我发现这个但是我我不太确定它是否正常工作,或者我不知道如何使用它:

I also need the same for the UI library, i found this but I am not very sure if it works properly, or maybe I don't know how o use it:

//Get version: $.ui.version //Comnpare version var version_required = 1.7.1 version = $.ui ? $.ui.version || "pre "+version_required : 'not found';

谢谢

推荐答案

这可能适合你:

if (typeof jQuery != 'undefined' && /[1-9]\.[7-9].[1-9]/.test($.fn.jquery)) { // jQuery is loaded and is at least version 1.7.1 }

同样,UI的几乎相同:

Likewise, it's almost the same for the UI:

if (typeof jQuery.ui != 'undefined' && /[1-9]\.[7-9].[1-9]/.test($.ui.version)) { // jQuery UI is loaded and is at least version 1.7.1 }

首先检查以确保jQuery可用,然后使用一些简单的正则表达式模式来测试版本号是否在可接受的范围内。

First it checks to make sure jQuery is available and then it uses some simple regex pattern to test that the version numbers are within an acceptable range.

UPDATE :这也适用于jQuery 2和3.

UPDATE: This will also work with jQuery 2 and 3.

更多推荐

如何检测是否安装了Jquery和Jquery UI,以及安装了哪些版本?

本文发布于:2023-11-02 10:12:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1552097.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:安装了   版本   Jquery   UI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!