【发布时间】:2011-01-15 00:18:24
【问题描述】:
我正在尝试编写一个 jQuery 语句来将当前单击的表行更改为不同的前景色,同时使所有同级表行颜色相同。基本上使它看起来像点击的行是活动的。这是我到目前为止所拥有的,这是第一次工作,但第二次它永远不会将所有兄弟姐妹设置为未选择的颜色。
<script type="text/javascript">
function changeRows(currentRow) {
$(currentRow).css('color', 'green'); // change clicked row to active color
$(currentRow).parent().siblings().css('color', 'red'); // change all the rest to non active color
}
</script>
<table>
<tr>
<td onclick="changeRows(this)">123
</td>
</tr>
<tr>
<td onclick="changeRows(this)">1234
</td>
</tr>
<tr>
<td onclick="changeRows(this)">12345
</td>
</tr>
<tr>
<td onclick="changeRows(this)">123456
</td>
</tr>
</table>
【问题讨论】:
标签: jquery