jQuery :text 选择器

实例

选择所有 type="text" 的 <input> 元素:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
  5. <script>
  6. $(document).ready(function(){
  7. $(":text").css("background-color", "red");
  8. });
  9. </script>
  10. </head>
  11. <body>
  12. <form action="">
  13. 名称: <input type="text" name="user"><br>
  14. 密码: <input type="password" name="password"><br>
  15. <button type="button">无用的按钮</button>
  16. <input type="button" value="另一个无用按钮"><br>
  17. <input type="reset" value="重置">
  18. <input type="submit" value="提交"><br>
  19. </form>
  20. </body>
  21. </html>

定义与用法

:text 选择器选择所有 type="text" 的 input 元素


语法

  1. $(":text")

分类导航