Blogger Information
Blog 34
fans 2
comment 0
visits 23161
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
12月19号作业 jquery选择器
遗忘了寂寞
Original
699 people have browsed it

1、引入jquery

  1. <script src="jquery-3.4.1.min.js" type="text/javascript"></script>

2、jquery怎么使用,案例获取一个文本框的值

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title></title>
  6. <script src="jquery-3.4.1.min.js" type="text/javascript"></script>
  7. </head>
  8. <body>
  9. <input type="text" id="usename" value="admin" />
  10. <script type="text/javascript">
  11. var usename=$('#usename').val();
  12. alert(usename);
  13. </script>
  14. </body>
  15. </html>

jquery选择器

html元素:

  1. <div class="mydiv" style="background: #000;" id="div_back">黑色</div>
  2. <div class="mydiv" style="background: #ff0000;" id="div_red">红色</div>
  3. <div class="mydiv" style="background: #00ff00;" id="div_green">
  4. <p id="a">div中的p标签</p>
  5. <div>
  6. <p id="b">div中的div的p标签</p>
  7. <p id="c">p3</p>
  8. </div>
  9. <p id="d">pd</p>
  10. <div style="background: yellow">第二个div</div>
  11. </div>
  12. <p id="4">我是p标签</p>

1、ID选择器

  1. <script type="text/javascript">
  2. //id选择器
  3. var div = $('#div_red');
  4. console.log(div);
  5. </script>

2、class选择器

  1. <script type="text/javascript">
  2. //class选择器
  3. var div = $('.mydiv');
  4. console.log(div);
  5. </script>

3、element选择器

  1. <script type="text/javascript">
  2. //element选择器
  3. var div = $('div');
  4. console.log(div);
  5. </script>

4、后代元素选择器

  1. <script type="text/javascript">
  2. //后代元素选择器
  3. var div = $('div p');
  4. console.log(div);
  5. </script>

5、直接子元素选择器

  1. <script type="text/javascript">
  2. //直接子元素选择器
  3. var div = $('div>p');
  4. console.log(div);
  5. </script>

6、相邻兄弟元素选择器(只向后选择相邻的兄弟元素)

  1. <script type="text/javascript">
  2. //相邻兄弟元素选择器(只向后选择相邻的兄弟元素)
  3. var div = $('div+p');
  4. console.log(div);
  5. </script>

7、兄弟元素选择器(向后选择所有兄弟元素)

  1. <script type="text/javascript">
  2. //兄弟元素选择器(向后选择所有兄弟元素)
  3. var div = $('div~p');
  4. console.log(div);
  5. </script>

Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:图文并茂, 非常的直观, 不错的
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post