jQuery_多库共存

<!--@description-->
<!--@author beyondx-->
<!--@date Created in 2022/08/02/ 17:02-->
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>标题</title>
</head>
<body>

<script src="heima.js"></script>
<script src="jquery-1.12.4.js"></script>
<script src="jquery-3.0.0.js"></script>

<script>
    //1.如何查看jQuery的版本?
    //通过jQuery文件名来查看jQuery的版本是不靠谱的做法.
    //通过以下四种方式可以查看jQuery的版本.
    // console.log(jQuery.fn.jquery);
    // console.log(jQuery.prototype.jquery);
    // console.log($.fn.jquery);
    // console.log($.prototype.jquery);

    //2.如果引入了多个jQuery文件. 那使用的$是哪一个jQuery文件中的呢?
    //那个文件后引入,使用的$就是谁的.
    // console.log($.fn.jquery);

    //3.多库共存
    // var _$ = $.noConflict(); // 后面引入的 把 $的控制权 释放掉
    //
    // // 自执行函数
    // (function () {
    //   // 在这个 自执行函数中, 就可以 继续使用 $了
    // }(_$));
    //
    // console.log(_$.fn.jquery); // 3.0.0 替代品
    //
    // console.log($.fn.jquery); // 1.12.4
    // console.log(jQuery.fn.jquery); // 3.0.0

    //4.多库共存2
    // console.log($);
    // console.log($.fn.jquery);

    var _$300 = $.noConflict(); // 3.0版本的 jQuery, 把 $ 的控制权 给释放了
    // console.log($.fn.jquery);

    var _$1124 = $.noConflict(); // 1.12.4版本的 jQuery, 把 jQuery 的 控制权, 也给释放了

    console.log($); // {name: '黑马程序员'}
    console.log(_$1124.fn.jquery); // 1.12.4
    console.log(_$300.fn.jquery); // 3.0.0

</script>
</body>
</html>

在这里插入图片描述

posted on 2022-08-02 17:43  beyondx  阅读(22)  评论(0编辑  收藏  举报

导航