作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
"和children()-6ren"> "和children()-HTML 代码: The first row The first row The second row The second row -6ren">
HTML 代码:
<table>
<tr>
<td>The first row</td> <td>The first row</td>
</tr>
<tr>
<td>The second row</td> <td>The second row</td>
</tr>
<tr>
<td>The third row</td> <td>The third row</td>
</tr>
<tr>
<td>The forth row</td> <td>The forth row</td>
</tr>
</table>
<hr>
<table>
<tr>
<td>The first row</td> <td>The first row</td>
</tr>
<tr>
<td>The second row</td> <td>The second row</td>
</tr>
<tr>
<td>The third row</td> <td>The third row</td>
</tr>
<tr>
<td>The forth row</td> <td>The forth row</td>
</tr>
</table>
jQuery 代码:
$(function () {
$("table:first tr").css("background", "#ffbbbb"); //work
$("table:last>tr").css("background", "#ffbbbb"); //not work
$("table:last").children("tr").css("background", "#ffbbbb"); //not work
});
结果:第一个表格的背景已更改,但第二个表格未更改。似乎空格选择器有效,但“>”和“children()”选择器不起作用,为什么?
工作示例: https://jsfiddle.net/6knk67gd/1/
我已经检查了这两个选择器的用法,但仍然在我的代码中找不到任何问题。请告诉我如何正确使用,谢谢~
最佳答案
即使我们没有创建 tbody
,默认情况下 dom 结构也会创建它,因此所有 tr
都将是 tbody/thead/tfooter 的子级
不是表
本身
尝试
$("table:last > tbody > tr").css("background", "#ffbbbb");
关于jquery:如何在表中使用 ">"和children(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31531342/
我是一名优秀的程序员,十分优秀!