JQuery summary of common techniques for manipulating tables
- 2020-03-30 02:43:04
- OfStack
1. Add styles for odd and even rows of the table
Not counting the head of the watch
2. Highlight the control line of the marquee
3. Highlight the control line of the check box
4. Table content screening
$(function(){
$('tr:odd').addClass("odd");
$('tr:even').addClass("even");
});
Not counting the head of the watch
$(function(){
$('tbody>tr:odd').addClass("odd");
$('tbody>tr:even').addClass("even");
});
2. Highlight the control line of the marquee
$('tobdy>tr').click(function(){
$(this).addClass('selected')
.siblings().removeClass('selected')
.end() //Returns the object again
.find(':radio').attr('checked',true);
});
3. Highlight the control line of the check box
$('tobdy>tr').click(function(){
if( $(this).hasClass('selected') ){ //Determines whether there is a selected highlighted style
$(this).removeClass('selected')
.find(':checkbox').attr('checked',false);
}else{
$(this).addClass('selected')
.find(':checkbox').attr('checked',true);
}
});
4. Table content screening
$(function(){
$('table tbody tr').hide()
.filter(":contains( li )").show();
});