Blogger Information
Blog 36
fans 1
comment 0
visits 28933
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
12月20日jQuery属性选择器.表单选择器-九期线上班
WJF
Original
1021 people have browsed it

jQuery属性选择器


  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. <h2 id="phpm">H2-1</h2>
  10. <li>li</li>
  11. <h2 id="emmmmm">H2-2</h2>
  12. <ul>
  13. <li id="mm222">1li</li>
  14. <li id="wjf">2li</li>
  15. <li id="mm555">3li</li>
  16. <li id="wjf">4li</li>
  17. <li id="mm221">5li</li>
  18. <li>6li</li>
  19. <li class="www">7li</li>
  20. <li class="ww">8li</li>
  21. <li class="w">9li</li>
  22. </ul>
  23. <h2>H2-3</h2>
  24. </body>
  25. <script>
  26. //first 选中第一个li元素
  27. $('li:first').css('background-color','#2d6a88');
  28. //选中ul下的 第一个li元素
  29. $('ul li:first').css('background-color','#0a68b4');
  30. //last 选中最后一个h2元素
  31. $('h2:last').css('background-color','#3a87ad');
  32. //eq选中指定下标元素
  33. $('li:eq(3)').css('background-color','#1a9c39');
  34. //gt 大于指定下标的元素
  35. $('li:gt(4)').css('background-color','#b25d25');
  36. //lt 小于指定下标的元素
  37. $('li:lt(2)').css('background-color','#d99925');
  38. // li[id]选中带有id的元素
  39. $('li[id]').css('color','#00ff00');
  40. // id=wjf 选中ID等于wjf的所有元素
  41. $('[id=wjf]').css('background-color','#ffff00');
  42. // id!=wjf 选中ID等于wjf的所有元素
  43. // $('[id!=wjf]').css('background-color','#ff9900');
  44. // li[class^=w] 选中li标签下class开头为w的所有元素
  45. $('li[class^=w]').css('background-color','#aa9999');
  46. // h2[id$=m] 选中h2标签下id结尾为m的所有元素
  47. $('h2[id$=m]').css('background-color','#aa0000');
  48. // 'li[id*=mm]'选中li标签下id中包含mm的元素
  49. $('li[id*=mm]').css('background-color','#888ccc');
  50. </script>
  51. </html>

jQuery表单选择器


  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. <form action="">
  10. <h2>注册账号</h2>
  11. <p>
  12. 邮箱:<input type="email" name="mail" value="33703259@qq.cn">
  13. </p>
  14. <p>
  15. 密码:<input type="password" name="pass" placeholder="密码6-18位">
  16. </p>
  17. <p>
  18. 确认密码:<input type="password" name="repass" placeholder="重新输入上方密码">
  19. </p>
  20. <p>
  21. 性别:<input type="radio" name="sex" value="nan">
  22. <input type="radio" name="sex" value="nv">
  23. </p>
  24. <button type="button" onclick="an()">提交注册</button>
  25. </form>
  26. <script>
  27. function an() {
  28. var mail = $('input[name="mail"]').val();
  29. var pass = $('input[name="pass"]').val();
  30. var repass = $('input[name="repass"]').val();
  31. var sex = $('input[name="sex"]:checked').val();
  32. if (mail==''){
  33. alert('邮箱信息未填写');
  34. return;
  35. }
  36. if(pass==''){
  37. alert('请填写密码');
  38. return;
  39. }
  40. if (pass!=repass){
  41. alert('两次密码不一致');
  42. return;
  43. }
  44. if (sex==undefined){
  45. alert('请选择您的性别');
  46. return;
  47. }else{
  48. alert('注册成功 账号资料登陆邮箱:'+mail+'登陆密码'+pass);
  49. }
  50. }
  51. </script>
  52. </body>
  53. </html>

Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:选择器, 有意思, 与css有相似之处, 但区别也很明显
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