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]')


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM