jQuery选择器,用逗号分隔的时候需要注意范围问题

时间:2023-03-09 22:34:58
jQuery选择器,用逗号分隔的时候需要注意范围问题

jQuery选择器,用逗号分隔的时候需要注意范围问题:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<meta charset="UTF-8">
<title>b index</title>
<link rel='stylesheet' type="text/css" href='b/css/bootstrap.css'>
</head>
<body style="margin:150px;">
<div>
<input type="checkbox" info="1" id="chkTestId"><label for="chkTestId">选择框</label>
<input type="checkbox" info="2" id="chkTest2Id"><label for="chkTestId">选择框2</label>
<button id="btnClickId">click me</button>
<input type="hidden" value="hiddenValue">
</div>
<div>
<table id="tblFormId">
<tr>
<td><input type="text" id="txtIn01Id"></td>
</tr>
<input type="text" id="txtIn02Id" >
</table>
<button id="btnUnderTblId">click me</button>
</div>
<script type="text/javascript" src="js/jquery-1.11.1.js"></script>
<script type="text/javascript" src="b/js/bootstrap.js"></script>
<script type="text/javascript" src="js/index020.js"></script> </body>
</html>

$('#tblFormId input,input[type=hidden]')选择结果为:

<input type="hidden" value="hiddenValue"><input type="text" id="txtIn01Id">

选择器中的逗号是两个条件的合集,第一个条件中的空格前面的部分不能带到下一个选择器中,

所以原来的意思是:$('#tblFormId input,#tblFormId input[type=hidden]')