歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> jQuery表單選擇器的基本語法

jQuery表單選擇器的基本語法

日期:2017/3/1 10:58:45   编辑:Linux編程

表單選擇器的語法:

:input 獲取所有的input、textarea、selecte

:text 獲取所有單行文本框

:password 獲取所有的密碼框

:radio 獲取所有的單選按鈕

:checkbox 獲取所有的復選框

:submit 獲取所有的提交按鈕

:image 獲取所有的圖像域

:reset 獲取所有的重置按鈕

:button 獲取所有的按鈕

:file 獲取所有的文件域

示例如下:

  1. <head>
  2. <title>使用jQuery表單過濾選擇器</title>
  3. <script language="javascript" type="text/javascript"
  4. src="../Jscript/jquery-1.5.2.js"></script>
  5. <style type="text/css">
  6. body{font-size:12px;text-align:center}
  7. form{width:241px}
  8. textarea,select,button,input,span{display:none}
  9. .btn {border:#666 1px solid;padding:2px;width:60px;
  10. filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr=#ffffff, EndColorStr=#ECE9D8);}
  11. .txt{border:#666 1px solid;padding:3px}
  12. .img{padding:2px;border:solid 1px #ccc}
  13. .div{border:solid 1px #ccc;background-color:#eee;padding:5px}
  14. </style>
  15. <script type="text/javascript">
  16. $(function(){ //顯示Input類型元素的總數量
  17. $("#form1 div").html("表單共找出 Input 類型元素:"+$("#form1 :input").length);
  18. $("#form1 div").addClass("div");
  19. })
  20. $(function(){ //顯示所有文本框對象
  21. $("#form1 :text").show(3000);
  22. })
  23. $(function(){ //顯示所有密碼框對象
  24. $("#form1 :password").show(3000);
  25. })
  26. $(function(){ //顯示所有單選按鈕對象
  27. $("#form1 :radio").show(3000);
  28. $("#form1 #Span1").show(3000);
  29. })
  30. $(function(){ //顯示所有復選框對象
  31. $("#form1 :checkbox").show(3000);
  32. $("#form1 #Span2").show(3000);
  33. })
  34. $(function(){ //顯示所有提交按鈕對象
  35. $("#form1 :submit").show(3000);
  36. })
  37. $(function(){ //顯示所有圖片域對象
  38. $("#form1 :image").show(3000);
  39. })
  40. $(function(){ //顯示所有重置按鈕對象
  41. $("#form1 :reset").show(3000);
  42. })
  43. $(function(){ //顯示所有按鈕對象
  44. $("#form1 :button").show(3000);
  45. })
  46. $(function(){ //顯示所有文件域對象
  47. $("#form1 :file").show(3000);
  48. })
  49. </script>
  50. </head>
  51. <body>
  52. <form id="form1">
  53. <textarea class="txt"> TextArea</textarea>
  54. <select><option value="0"> Item 0</option></select>
  55. <input type="text" value="Text" class="txt"/>
  56. <input type="password" value="PassWord" class="txt"/>
  57. <input type="radio" /><span id="Span1"> Radio</span>
  58. <input type="checkbox" /><span id="Span2"> CheckBox</span>
  59. <input type="submit" value="Submit" class="btn"/>
  60. <input type="image" title="Image" src="../Images/logo.gif" class="img"/>
  61. <input type="reset" value="Reset" class="btn"/>
  62. <input type="button" value="Button" class="btn"/>
  63. <input type="file" title="File" class="txt"/>
  64. <div id="divShow"></div>
  65. </form>
  66. </body>
  67. </html>
Copyright © Linux教程網 All Rights Reserved