![](/img/trans.png)
[英]jquery dataTables make my <thead> <tr> clickable but not change color on click
[英]Change Font color of tr with jQuery after click on image
我正在寻找一种使用jQuery更改tr字体颜色的方法。 每个tr的最后一个单元格中都有一个图标。 我想要单击它以更改tr的字体颜色。 我用过这个:
$('#documentsTable tr').live('click', function(){
但这是用于单击整行。 最好的管理方式是什么?
最好的祝福
假设您的图标类别为icon
:
$('#documentsTable .icon').live('click', function(){
$(this).closest("tr").css("color","yourColor");
});
您可以使用:last-child
伪选择器来匹配匹配集中每个元素的最后一个孩子(在这种情况下,是#documentsTable
中每个tr
的最后一个td
):
$('#documentsTable tr td:last-child').live('click', function(){
$(this).closest("tr").css({color: "#ff0000"});
});
要将click事件处理程序附加到该td
的图像,只需将img
添加到选择器的末尾:
#documentsTable tr td:last-child img
这是一个有效的例子 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.