<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="js/jquery.js"></script>
<script>
window.onload = function(){
document.getElementById('btnok').onclick = function(){
//1.匹配第一个单元格
//$('td:first').html('test');
//2.匹配最后一个单元格
//$('td:last').html('test');
//3.通过odd和even实现隔行变色
//$('td:odd').css('backgroundColor','red');
//4.匹配索引为5的单元格
//$('td:eq(5)').css('backgroundColor','red');
//5匹配索引大于5的所有单元格
//$('td:gt(5)').css('backgroundColor','red');
//6.匹配索引小于5的所有单元格
//$('td:lt(5)').css('backgroundColor','red');
//7.匹配除索引5以外的所有td元素
$('td:not(td:eq(5))').css('backgroundColor','red');
}
}
</script>
</head>
<body>
<input type="button" id="btnok" value="匹配" />
<br/>
<table width="800" border="1">
<tr>
<td>0</td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
</table>
</body>
</html>
转载于:https://blog.51cto.com/leigood/1703923