Blogger Information
Blog 36
fans 1
comment 0
visits 28784
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
12月19日jQuery选择器-九期线上班
WJF
Original
851 people have browsed it

jQuery选择器


var n1 = $('#a'); 给某个元素ID赋值


var n2 = $('.n'); 给元素类赋值


var n3 = $('.n p'); 给元素后匹配项赋值


var n4 = $('.n > p'); 父元素下所有直接匹配的子元素


var n5 = $('.n + p'); 指定元素后紧贴的元素


var n6 = $('.n ~ p'); 指定元素所有同级元素


  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>jQuery选择器</title>
  6. <script src="jquery-3.4.1.min.js"></script>
  7. </head>
  8. <body>
  9. <div class="n">
  10. <p id="a" style="background-color: #2d6a88">PHP中文网</p>
  11. <ul id="b" style="background-color: #0a68b4">PHP.CN</ul>
  12. <ul id="c" style="background-color: #3a87ad"><p id="d">PHP</p></ul>
  13. <div id="e" style="background-color: #1a9c39"> <li id="f"> js </li> </div>
  14. </div>
  15. <p id="g" style="background-color: #0C9A9A"> jQuery </p>
  16. </body>
  17. <script>
  18. //给某个元素ID赋值
  19. var n1 = $('#a');
  20. console.log(n1);
  21. //给元素类赋值
  22. var n2 = $('.n');
  23. console.log(n2);
  24. //给元素后匹配项赋值
  25. var n3 = $('.n p');
  26. console.log(n3);
  27. //父元素下所有直接匹配的子元素
  28. var n4 = $('.n > p');
  29. console.log(n4);
  30. //指定元素后紧贴的元素
  31. var n5 = $('.n + p');
  32. console.log(n5);
  33. //指定元素所有同级元素
  34. var n6 = $('.n ~ p');
  35. console.log(n6);
  36. </script>
  37. </html>
Correcting teacher:西门大官人西门大官人

Correction status:qualified

Teacher's comments:jquery选择器选择的是dom元素,不是赋值
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