jQuery 的顶级对象$

1.$是jQuery的别称,在代码中可以使用jQuery代替$,但一般为了方便,通常都直接使用$。

2.$是jQuery的顶级对象,相当于原生JavaScript中的window。把元素利用$包装成Query对象,就可以调用jQuery的方法。

代码示例:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="jQuery.mini.js"></script>
    <style>
        div {
            width: 200px;
            height: 200px;
            background-color: pink;
        }
    </style>
</head>

<body>
    <script>
        // 1.$是jQuery的别称(另外的名字)
        // $(function () {
        //     alert(11)
        // })
        jQuery(function () {
            // alert(22)
            // $('div').hide()
            jQuery('div').hide()
        })
        // 2.$同时也是jQuery的顶级对象
    </script>
    <div></div>
</body>


</html>

 

posted @ 2022-04-17 09:44  今天穿秋裤了吗  阅读(121)  评论(0)    收藏  举报