如何在点击时更改HTML行颜色 [英] how to change the Html row colur on click
本文介绍了如何在点击时更改HTML行颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有
包含行如下的html表
I have
a html table containing Rows as Below
<html>
<head></head>
<body>
<table>
<tr><td><a href="abcd.aspx">ABCD</></td>
</tr>
<tr><td><a href="xyz.aspx">XYZ</></td>
</tr>
</table>
</body>
</html>
该表格设置在母版页上
现在,我希望单击链接ABCD或XYZ
必须选择整行,并且
所选行的颜色必须更改
相应地.
可以做到吗.我该怎么做
请协助.
this Table set on the Masterpage
Now I want that on click of link ABCD or XYZ
whole row must get selected and also the
colour of that selected rows must change
accordingly.
can this be done.How can i do this
please assist.
推荐答案
<table>
<tr>
<td onclick="changeRowColor(this)">ABC
</td>
</tr>
<tr>
<td onclick="changeRowColor(this)">DEF
</td>
</tr>
<tr>
<td onclick="changeRowColor(this)">...
</td>
</tr>
<tr>
<td onclick="changeRowColor(this)">XYZ
</td>
</tr>
</table>
<script type="text/javascript">
function changeRowColor(currentRow) {
(currentRow).css('color','green'); //将点击的行更改为活动颜色
(currentRow).css('color', 'green'); // change clicked row to active color
(currentRow).parent().siblings().css('color','red'); //将其余所有颜色更改为非活动颜色 } < /script >
(currentRow).parent().siblings().css('color', 'red'); // change all the rest to non active color } </script>
请在您的页面中引用JQuery库,并让我知道您是否在同一页面上有任何查询
谢谢,
Ambesha
Please refer JQuery Library in you page, and let me know if you have any query on the same
Thanks,
Ambesha
这篇关于如何在点击时更改HTML行颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文