jquery的:hidden选择器为什么会选中221f08282418e2996498697df914ce4e标签
<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"))一下就知道了。选中的不是<select>,是里面的<option>:
[option, input, div]
改为用$(#form1 > :hidden)来选择就好了,这样就只会选择表单下的直接子元素,因此不会选择option
select没有结束标签?
因为你选的是隐藏的标签,而option就是隐藏的标签。。select没有隐藏所以不会选中,
以上就是jquery :hidden选择器选中<select>标签的详解的详细内容。