Blogger Information
Blog 27
fans 0
comment 0
visits 17281
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
035-12月19日-JS第4节-jquery选择器1
冇忉丼
Original
667 people have browsed it

选择器6种:

1.id和class选择器:符号标识与css一样
2.标签选择器:除了基本的按标签名选择以外,还有
(1)祖先 后代(2)父 > 子(3)老n + 老(n+1)(4)老n ~ 老n所有弟与妹
示例:

  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport"
  6. content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  7. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  8. <script type="text/javascript" src="../jquery-3.4.1.js"></script>
  9. <title>jquery基本选择器--6种</title>
  10. <style>
  11. div{
  12. width: 400px;
  13. height: 150px;
  14. }
  15. .p1{
  16. background: yellow;
  17. }
  18. .p2{
  19. background: yellowgreen;
  20. }
  21. </style>
  22. </head>
  23. <body>
  24. <div style="background:red;">
  25. div1
  26. <p class="p1">1</p>
  27. <p class="p2">2</p>
  28. <input type="text" id="user">
  29. <input type="text">
  30. </div>
  31. <div style="background:green;">
  32. div2
  33. <p class="p1">I
  34. <input type="text">
  35. </p>
  36. <p class="p2">II</p>
  37. </div>
  38. <div style="background:blue;">
  39. div3
  40. <p class="p1"></p>
  41. <p class="p2"></p>
  42. </div>
  43. <button onclick="tag()">按标签选</button>
  44. <button onclick="qClass()">按class选</button>
  45. <button onclick="grandTag()">标签下的所有子孙标签</button>
  46. <button onclick="sonTag()">标签下的所有子标签</button>
  47. <button onclick="bro1()">标签后面紧跟的某标签</button>
  48. <button onclick="broAll()">标签后面所有的兄弟标签</button>
  49. <script type="text/javascript">
  50. function tag() {
  51. return $("p").css("fontsize","50px");
  52. // var p1 = $('p').val();
  53. // alert(p1);
  54. }
  55. function qClass() {
  56. var p2 = $('.p2');
  57. var arg2 = $("#user");
  58. console.log(p2);
  59. console.log(arg2);
  60. }
  61. function grandTag() {
  62. var arg3 = $('div input ');
  63. console.log(arg3);
  64. }
  65. function sonTag() {
  66. var arg4 = $('div > input ');
  67. console.log(arg4);
  68. }
  69. function bro1() {
  70. var arg5 = $('p + input ');
  71. console.log(arg5);
  72. }
  73. function broAll() {
  74. var arg6 = $('p ~ input ');
  75. console.log(arg6);
  76. }
  77. </script>
  78. </body>
  79. </html>
Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:jquery就的选择器是一个亮点
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