Home > Web Front-end > JS Tutorial > jquery's discussion on the hiding and display of tables and table columns_jquery

jquery's discussion on the hiding and display of tables and table columns_jquery

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 17:31:14
Original
1209 people have browsed it

1. Regarding the hiding and display of specified columns in specified tables

Copy the code The code is as follows:

$(" :checkbox[name*=month]").each(function(){
if(!$(this).attr("checked")){
var colnum = $(this).val() ;
$("#listPage").find('tr').find("td:eq(" colnum.toString() ")").hide();
$("#listPage" ).find('tr').find("th:eq(" colnum.toString() ")").hide();
} else {
var colnum = $(this).val( );
$("#listPage").find('tr').find("td:eq(" colnum.toString() ")").show();
$("#listPage ").find('tr').find("th:eq(" colnum.toString() ")").show();
}
});

Or:
Copy code The code is as follows:

$(document).ready(function( ){
$("td:eq(2)",$("tr")).hide();
$("td:eq(3)",$("tr")). hide();
$("td:eq(4)",$("tr")).hide();
$("#button1").click(function(){
$("td:eq(2)",$("tr")).toggle(1000); //Set to 0 to indicate no animation, 1000 to show or hide in 1 second
$("td :eq(3)",$("tr")).toggle(1000);
$("td:eq(4)",$("tr")).toggle(1000);
});
});

2. Get the number of columns in the table
Copy code The code is as follows:

var col = $("#listPage").find("th").prevAll().length;//Get the number of table columns
for(var i =0;i<=col;i ){
if($("#listPage").find('tr').find("th:eq(" i.toString() ")").css ("display")=='none') {//Determine whether the column is hidden
$("input[value=" i "]").attr("checked",false);
} else {
$("input[value=" i "]").attr("checked",true);
}
}

3. In jquery if If you want to find a visible element, use:visible
For example, $("tr:visible")
If you want to find a hidden element, you can use
$("tr:not(':visible')") That's it.
Related labels:
Statement of this Website
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
Latest Issues
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template