1.通配符
$("input[id^='code']");//id属性以code开始的所有input标签
$("input[id$='code']");//id属性以code结束的所有input标签
$("input[id*='code']");//id属性包含code的所有input标签
2.根据索引选择
$("tbody tr:even"); //选择索引为偶数的所有tr标签
$("tbody tr:odd"); //选择索引为奇数的所有tr标签
3.获得jqueryObj下一级节点的input个数
jqueryObj.children("input").length;
4.获得class为main的标签的子节点下所有<a>
标签
$(".main > a");
5.选择紧邻标签
jqueryObj.next("div");//获取jqueryObj标签的后面紧邻的一个div,nextAll获取所有
6.筛选器
$("#code input:not([id^='code'])");//id为code标签内不包含id以code开始的所有input标签
代码:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>测试页面</title>
<link rel="stylesheet" type="text/css" href="../css/easyui/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../css/easyui/icon.css">
<script src="../js/jquery/jquery.min.js"></script>
<script src="../js/easyui/jquery.easyui.min.js"></script>
</head>
<body>
<h2>Custom DataGrid Pager</h2>
<table id="dg">
<tr>
<th><input id="tr1td1" value="11"></th>
<th><input id="tr1td2" value="12"></th>
<th><input id="tr1td3" value="13"></th>
<th><input id="tr1td4" value="14"></th>
</tr>
<tr>
<td><input id="tr2td1" value="21"></td>
<td><input id="tr2td2" value="22"></td>
<td><input id="tr2td3" value="23"></td>
<td><input id="tr2td4" value="24"></td>
</tr>
<tr>
<td><input id="tr3td1" value="31"></td>
<td><input id="tr3td2" value="32"></td>
<td><input id="tr3td3" value="33"></td>
<td><input id="tr3td4" value="34"></td>
</tr>
</table>
<div>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="tpfcs()">通配符测试</a>
</div>
<script>
$(function () {
});
function tpfcs() {
var key = 'td1';
var a = $("#dg input[id*="+key+"]");
console.log(a);
}
</script>
</body>
</html>
结果: