:reset
选择所有类型为重置的元素。
jQuery(":reset")
:reset
等价于[type="reset"]
注意
- 因为
:reset
是一个 jQuery 延伸出来的选择器,并不是的CSS规范的一部分,使用:reset
查询不能充分利用原生DOM提供的querySelectorAll()
方法来提高性能。为了当使用:reset
的时候在现代浏览器上获得更佳的性能,首先使用纯CSS选择器选择元素,然后使用[type="reset"]
代替.
例子
查找所有重置按钮。
<!DOCTYPE html> <html> <head> <style> textarea { height:45px; } </style> <script src="https://www.lanmper.cn/static/js/jquery-3.5.0.js"></script> </head> <body> <form> <input type="button" value="Input Button"/> <input type="checkbox" /> <input type="file" /> <input type="hidden" /> <input type="image" /> <input type="password" /> <input type="radio" /> <input type="reset" /> <input type="submit" /> <input type="text" /> <select><option>Option<option/></select> <textarea></textarea> <button>Button</button> </form> <div> </div> <script>var input = $("input:reset").css({background:"yellow", border:"3px red solid"}); $("div").text("For this type jQuery found " + input.length + ".") .css("color", "red"); $("form").submit(function () {return false; }); // so it won't submit </script> </body> </html>