123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <!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>基本选择器</title>
- <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
- <script>
- // 如果JQ代码写在body前面,必须将代码写在ready事件中,ready事件表示所有DOM加载完成之后才执行
- // $(document).ready(function(){
- // console.log($('.box'))
- // })
- // 简化写法
- // $(function(){
- // console.log($('.box'))
- // })
- // $(function(){//ready事件可以写多个,相当于JS中的onload事件,但是跟onload的区别是:可以出现多次,而onload在一个页面中只能出现一次。
- // console.log($('.box'))
- // })
- // id
- // $(function(){
- // $('#box').css({
- // color:'blue',
- // background:'#eee'
- // })
- // })
- // class
- // $(function(){
- // $('.box').css({
- // color:'red',
- // background:'#eee',
- // 'margin-bottom':'10px'
- // })
- // })
- // 标签
- // $(function(){
- // $('p').css({
- // color:'red',
- // background:'#eee',
- // 'margin-bottom':'10px'
- // })
- // })
- // 星号(*)
- // $(function(){
- // console.log($('*'))
- // })
- // 逗号(,)
- $(function(){
- $('#box,.box,p').click(function(){
- console.log($(this).html())
- })
- })
- </script>
- </head>
- <body>
- <div class="box">class1</div>
- <div class="box">class2</div>
- <div class="box">class3</div>
- <div id="box">id</div>
- <p>p标签1</p>
- <p>p标签2</p>
- <p>p标签3</p>
- </body>
- <!-- <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
- <script>
- console.log($('.box'))
- </script> -->
- </html>
|