如何使用Jquery突出显示表中选定的行? [英] How to highlight the selected row in a table using Jquery?
本文介绍了如何使用Jquery突出显示表中选定的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码类似 这
当单击复选框时,我想突出显示该行。我不想对表使用id。因为我有很多相同的格式的表,我想应用CSS复选框单击使用单个Jquery函数。如何实现这个?
When the checkbox is clicked I want to highlight that row.I don't want to use id for a table. Because I am having lot of tables in the same format and I want to apply the css when checkbox is clicked by using single Jquery function.How can I achieve this?
推荐答案
$(document).ready(function()
{
$('td input[type="checkbox"]').click(function(){
if ($(this).is(':checked')){
$(this).parent().addClass('highlighted');
$(this).parent().siblings().addClass('highlighted');
} else if($(this).parent().is('.highlighted')) {
$(this).parent().removeClass('highlighted');
$(this).parent().siblings().removeClass('highlighted');
}
});
});
有一些不同的方法可以使行突出显示。但我只是添加了一个突出显示的类,它有一个背景颜色,并将其设置为所有的tds
There's some different ways to get the row highlighted. But I just added a class called highlighted that had a background color and set it to all the tds
这篇关于如何使用Jquery突出显示表中选定的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文