jQuery的顶级对象是$,它是jQuery的别称,相当于JS中的window对象。在代码中,我们可以使用jQuery来代替$,但为了方便起见,我们通常使用$。,$可将元素包装为jQuery对象,以便调用jQuery的方法。
示例:
(1)使用$符号
<script src="jQuery.js"></script>
<style>
div {
width: 100px;
height: 100px;
}
</style>
</head>
<body>
<script>
$(function () {
$('div').css('background-color', 'green');
})
</script>
<div></div>
</body>
效果图:
(2)使用jQuery
<script src="jQuery.js"></script>
<style>
div {
width: 100px;
height: 100