加载中...

:password


概述    password selector

返回值:Array<Element(s)>

描述:选择所有类型为密码的元素。

  • V : 1.0jQuery( ":password" )

$(':password')等价于$('[type=password]')。如同其他伪类选择器(那些以“:”开始)建议前面加上一个标记名称或其他选择器;否则,通用选择("*")被默认使用。换句话说$(':password') 等同于 $('*:password'),所以应该使用$('input:password')

Additional Notes(其他注意事项):

  • 因为:password 是一个 jQuery 延伸出来的选择器,并不是的CSS规范的一部分,使用:password 查询不能充分利用原生DOM提供的querySelectorAll() 方法来提高性能。为了当使用:password 的时候在现代浏览器上获得更佳的性能,首先使用纯CSS选择器选择元素,然后使用[type="password"]代替.

示例

实例

查找所有密码框

HTML 代码:
  1. <form>
  2. <input type="text" />
  3. <input type="checkbox" />
  4. <input type="radio" />
  5. <input type="image" />
  6. <input type="file" />
  7. <input type="submit" />
  8. <input type="reset" />
  9. <input type="password" />
  10. <input type="button" />
  11. <select><option/></select>
  12. <textarea></textarea>
  13. <button></button>
  14. </form>
jQuery 代码:
  1. $(":password")
结果:
  1. [ <input type="password" /> ]

实例

Finds all password inputs.

  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>password demo</title>
  6. <style>
  7. textarea {
  8. height: 45px;
  9. }
  10. </style>
  11. <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
  12. </head>
  13. <body>
  14. <form>
  15. <input type="button" value="Input Button">
  16. <input type="checkbox">
  17. <input type="file">
  18. <input type="hidden">
  19. <input type="image">
  20. <input type="password">
  21. <input type="radio">
  22. <input type="reset">
  23. <input type="submit">
  24. <input type="text">
  25. <select>
  26. <option>Option</option>
  27. </select>
  28. <textarea></textarea>
  29. <button>Button</button>
  30. </form>
  31. <div></div>
  32. <script>
  33. var input = $( "input:password" ).css({
  34. background: "yellow",
  35. border: "3px red solid"
  36. });
  37. $( "div" )
  38. .text( "For this type jQuery found " + input.length + "." )
  39. .css( "color", "red" );
  40. // Prevent form submission
  41. $( "form" ).submit(function() {
  42. return false;
  43. });
  44. </script>
  45. </body>
  46. </html>
运行一下


还没有评论.