jquery discussion on table and table column hiding and displaying problems _jquery

Source: Internet
Author: User
1. About the specified table specify column hide display
Copy Code code 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 code 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 means no animation, 1000 is 1 seconds to show or hide
$ ("Td:eq (3)", $ ("tr")). Toggle (1000);
$ ("Td:eq (4)", $ ("tr")). Toggle (1000);
});
});

2. Get the number of columns in the table
Copy Code code 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. If you want to find a visible element in jquery: visible
For example $ ("tr:visible")
If you want to find what is not displayed, you can use the
$ ("Tr:not (': Visible ')") on the line.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.