我有这样的表格:
<table id="tlist" border="1" cellpadding="0" cellspace="0">
<thead><tr><th>sort</th></tr></thead>
<tbody>
<tr class="lrow"><td>first</td>
</tr>
<tr class="lrow"><td>second</td>
</tr>
<tr class="lrow"><td>third</td>
</tr>
</tbody>
</table>
我想点击tbody的第一行。我尝试过一些解决方案。
我尝试过的:
//$("#tlist tr").first().css("background-color", "#00f");
$("#tlist").find("tr").eq(1).addClass("highlight");
$("#tlist").find("tr").eq(1).trigger("click");
$(".lrow").click(function() {
alert("c");
});
$("#tlist tr").on('click', function() {
alert("d");
});
我使用 jquery 在准备好的文档上运行上面的代码。它不起作用。 highlight
已添加到目标行。但颜色没有改变。我把它放在jfiddle 。
有人有一些adive吗?感谢您抽出时间。
最佳答案
在你的 fiddle 中首先包含 jquery 库并查看 css 中的以下错误
.highlight td{
background-color: "#0f0";
}
改成这个
.highlight td{
background-color: #0f0; // remove double quotes
}
关于javascript - 单击不会在 tbody 的第一行触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25526162/