1

如何使用 jQuery 1.3.2 选择所有没有任何后代 td 元素的表元素?

4

2 回答 2

6

你可以试试:

$("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>
于 2009-10-21T16:50:53.893 回答
1

您正在寻找CSS:not()选择器

table *:not(td)

应该这样做。

编辑:呸,误读了你想要的。

于 2009-10-21T16:51:21.910 回答