我在我的应用程序上创建了一个表,代码如下
<table class="spreadsheet">
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>5</td>
<td>6</td>
</tr>
</table>
我使用以下 jQuery 代码单击选择一行
$("tr").click(function(){
$(this).toggleClass("otherstyle");
}
我的CSS是
tr.otherstyle td
{
background-color: #d1db3e;
color:#000;
}
我希望当我点击一行时,其他行被取消选中, 并且只选择一行。
我们如何创建它?
最佳答案
$("table.spreadsheet tr").click(function(){
$("table.spreadsheet tr").removeClass("otherstyle");
$(this).toggleClass("otherstyle");
});
见一个 working demo
关于jquery - 如何使用 jQuery 只选择一行表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2735381/