【发布时间】:2009-10-21 16:48:19
【问题描述】:
如何使用 jQuery 1.3.2 选择所有没有任何后代 td 元素的表格元素?
【问题讨论】:
如何使用 jQuery 1.3.2 选择所有没有任何后代 td 元素的表格元素?
【问题讨论】:
你可以试试:
$("table:not(:has(tbody > tr > td))").doStuff();
工作示例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$("table:not(:has(tbody > tr > td))").css("background", "yellow");
});
</script>
<style type="text/css">
table { border-collapse: collapse; }
td, th { border: 1px solid black; }
</style>
</head>
<body>
<table>
<tr>
<td>First table</td>
</tr>
</table>
<table>
<tr>
<th>Second table</th>
</tr>
</table>
</body>
</html>
【讨论】:
【讨论】:
tables 通常永远不会拥有tds 的直系子级,因此这不会像所写的那样工作。