Blogger Information
Blog 42
fans 5
comment 0
visits 38580
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
jq 选择器,属性选择器,子类选择器,表单选择器
张浩刚
Original
1386 people have browsed it
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>Document</title>
  8. <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
  9. </head>
  10. <body>
  11. <ul>
  12. <li>list item 1</li>
  13. <li class='twor'>list item 2</li>
  14. <li id='three' name='three'>list item 3</li>
  15. <li class='four'>list item 4</li>
  16. <li name='five'>list item 5</li>
  17. <li name='haha man'><span>list item 6</span></li>
  18. <li name='ffic'>list item 7</li>
  19. </ul>
  20. <ul>
  21. <li>list item 1</li>
  22. </ul>
  23. <button>点击</button>
  24. <script>
  25. $('button').on('click', function(){
  26. // $('li:odd').css('color','red');//选中偶数
  27. // $('li:even').css('color','red');//选中奇数
  28. // $('li:eq(1)').css('color','red'); //从0开始,1即为第二个
  29. // $('li:gt(2)').css('color','red');//选中起始位以后的所有li
  30. // $('li[id]').css('color','red'); //选中li下所有含id属性的li
  31. // $('li[id="three"]').css('color','red'); //选中id=three的li
  32. // $('li[class="four"]').css('color','red'); //选中class=four的li
  33. // $('li[name="five"]').css('color','red'); //选中name=five的li
  34. // $('li[name^="f"]').css('color','red'); //选中name属性中开头为f的li
  35. // $('li[class$="r"]').css('color','red'); //选中class属性中结尾为r的li
  36. // $('li[class*="r"]').css('color','red'); //class属性中只要有r的就都选中
  37. // $('li[name~="man"]').css('color','red'); //选中name属性中有空的 man的li
  38. // $('li[id][name^="t"]').css('color','red'); //多重属性筛选 ,选中所有含id的且name开头为t的li
  39. // $('li:first').css('color','red'); //第一个
  40. // $('li:first-child').css('color','red');//第一个
  41. // $('li:first-of-type').css('color','red');//第一个
  42. // $('li:last').css('backgroundColor','blue');//最后一个
  43. // $('li:last-of-type').css('color','red');//最后一个
  44. // $('li:last-child').css('color','red');//最后一个
  45. // $('li:nth-child(2)').css('color','red'); //第二个
  46. // $('li:nth-of-type(2)').css('color','red'); //第二个
  47. });
  48. </script>
  49. </body>
  50. </html>

from选中

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>Document</title>
  8. <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
  9. </head>
  10. <body>
  11. <form action="" method="GET">
  12. <p><label for="text">会员名:<input type="text" name="text" id="text"></label></p>
  13. <p><label for="password">登录密码<input type="password" name="password" id="password"></label></p>
  14. <p><label for="re_password">再次密码<input type="password" name="password" id="re_password"></label></p>
  15. <p>
  16. <label for="sex1">性别:
  17. <label for="sex1"><input type="radio" name="sex" id="sex1" value='1'></label>
  18. <label for="sex2"><input type="radio" name="sex" id="sex2" value="0"></label>
  19. </label>
  20. </p>
  21. <p>
  22. <label for="php">爱好:
  23. <label for="php"><input type="checkbox" name="check" id="php">php</label>
  24. <label for="javascript"><input type="checkbox" name="check" id="javascript">javascript</label>
  25. <label for="css"><input type="checkbox" name="check" id="css">css</label>
  26. <label for="python"><input type="checkbox" name="check" id="python" disabled>python</label>
  27. </label>
  28. </p>
  29. <p>
  30. <label for="">地区
  31. <select>
  32. <option value="郫都区">郫都区</option>
  33. <option value="锦江区">锦江区</option>
  34. <option value="青羊区">青羊区</option>
  35. <option value="高新区">高新区</option>
  36. </select>
  37. </label>
  38. </p>
  39. <button>点击</button>
  40. </form>
  41. <script>
  42. $('button').on('click', function () {
  43. if (!$('#text').val()) {
  44. alert('用户名不能为空');
  45. return false;
  46. }
  47. if (!$('input[name="password"]').val() || $('input[name="password"]').val() !== $('#re_password').val()) {
  48. alert('密码不能为空,或不相等');
  49. return false;
  50. }
  51. let sex = $('input[name="sex"]:checked').val();
  52. if( !sex ){
  53. alert('请选择性别');
  54. return false;
  55. }
  56. let select = $('input[name="check"]:checked').val();
  57. if( !select ){
  58. alert('请选择爱好');
  59. return false;
  60. }
  61. //获取shelect
  62. //$('select option:checked').val(); //获取选中的值,option中的value
  63. //$('select option:checked').text; // 选中option的汉字
  64. });
  65. </script>
  66. </body>
  67. </html>
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