我需要使用 jQuery 为下表的第一个和最后一个应用样式,编写了一些未触发的脚本..
<script>$("th:gt(0)").css("border-left", "none");</script>
<table>
<tr>
<th scope="col">one</th>
<th scope="col">two</th>
<th scope="col">three</th>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
</table>
任何帮助都会派上用场。
最佳答案
您可以使用 :first-child
和 :last-child
伪选择器:
$("table tr th:first-child, table tr th:last-child").css("border-left", "none");
要仅将 CSS 应用于最后一个 TH,您可以使用 .last()
,像这样(保持一行):
$("table tr th:first-child, table tr th:last-child").css("border-left", "none").last().css("border-right", "none");
关于jquery - 将 CSS 应用于表格的第一个和最后一个 TH,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7402763/