Home >Web Front-end >JS Tutorial >Summary of common techniques for operating tables with JQuery_jquery

Summary of common techniques for operating tables with JQuery_jquery

WBOY
WBOYOriginal
2016-05-16 16:51:351044browse

1. Add styles


$ (function(){
$('tr:odd').addClass("odd");
$('tr:even').addClass("even");
});

Does not count the head of the table
Copy the code The code is as follows:

$(function(){
$('tbody>tr:odd').addClass("odd");
$('tbody>tr:even').addClass("even");
});

2. Highlighting of radio button control rows
Copy code The code is as follows:

$('tobdy>tr').click(function(){
$(this).addClass('selected')
.siblings() .removeClass('selected')
.end() // Return the object again
.find(':radio').attr('checked',true);
});

3. Check box control row highlighting
Copy code The code is as follows:

$('tobdy>tr').click(function(){
if( $(this).hasClass('selected') ){ // Determine whether there is a selected highlight style
$(this).removeClass('selected')
.find(':checkbox').attr('checked',false);
}else{
$(this).addClass('selected ')
.find(':checkbox').attr('checked',true);
}
});

4. Table content filtering
Copy code The code is as follows:

$(function(){
$('table tbody tr ').hide()
.filter(":contains(李)").show();
});
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn