jquery的:hidden选择器为什么会选中
<html> <head> <title>forth.html</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <script type="text/javascript" src="../jquery.min.js"> </script> </head> <body> <form action="#" id="form1"> <select> <option>Option</option> </select> <input type="hidden"/><div style="display:none">test</div> </form> </body> <script type="text/javascript"> alert($("#form1 :hidden").length); </script> </html>
为什么结果是3,而不是2呢?谢谢。
console.log($("#form1 :hidden"))一下就知道了。选中的不是
[option, input, div]
改为用$("#form1 > :hidden")来选择就好了,这样就只会选择表单下的直接子元素,因此不会选择option
select没有结束标签?
因为你选的是隐藏的标签,而option就是隐藏的标签。。select没有隐藏所以不会选中,
以上就是jquery :hidden选择器选中<select>标签的详解的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号