前端(jQuery)(6)-- jQuery的扩展与noConflict

1、jQuery的扩展

  

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="jquery-3.3.1.min.js"></script>
    <script src="myjQuery.js"></script>
    <script>
        $(document).ready(function(){
           // $.myjq();
            $("div").myjq();
        });
    </script>
</head>
<body>
<div></div>
</body>
</html>

2、noConflict

代替掉美元符号,美元符号是jQuery的简写

noConflict是为了防止冲突

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="jquery-3.3.1.min.js"></script>
    <script>
        var myjq = $.noConflict();/*使用了这句话美元符号就没有效果了,需要将美元符号替换为jQuery*/

        /*jQuery(document).ready(function(){
            jQuery("#btn").click(function(){
                jQuery("div").text("newText");
            });
        });*/
        myjq(document).ready(function(){
            myjq("#btn").click(function(){
                myjq("div").text("newText");
            });/*上面那种方法和下面这种方法都是可以的*/
        });
    </script>
</head>
<body>
    <div>hello</div>
    <button id="btn">按钮1</button>
</body>
</html>
原文地址:https://www.cnblogs.com/foreverlin/p/10121558.html