There are many online, here are three kinds of:
The first is to use the ID, which can be used to dynamically set the ID of the TR when generating HTML, and is the simplest one to use, as follows:
HTML code
- < Table >
- < TR > < TD > This line does not hide </td></tr>
- < TR id="tr_1"><td> This line to hide </TD > </ TR >
- < TR id="tr_2"><td> This line to hide </ TD > </ TR >
- ...
- </ Table >
Then control explicit can be used directly
JS Code
- for (var i = 1; i < Tr_len; i++) { //tr_len is the number of TR to be controlled
- $ ("#tr_"+i). Hide ();
- }
The second method is to use $.each (), which needs to set the table ID as follows:
HTML code
- < Table id="TBL">
- < TR > < TD > This line does not hide </td></tr>
- < TR > < TD > This line to hide </td></tr>
- < TR > < TD > This line to hide </td></tr>
- ...
- </ Table >
Then control explicit can be used directly
JS Code
- $.each ($ ("#Tbl tr"), function(i) {
- if (i > 0) {
- this. style.display = ' None ';
- }
- });
The third method , through a property filter, requires that a specific attribute, such as class, be added to TR, as follows:
HTML code
- < Table id="TBL">
- < TR > < TD > This line does not hide </td></tr>
- < tr > < td class = "HID" > this line to hide </ TD > </ tr >
- < TR > < TD class="hid"> This line to hide </td></ TR>
- ...
- </ Table >
Then control explicit can be used directly
JS Code
- var trs = $ ("tr[class= ' hid ']");
- for (i = 0; i < trs.length; i++) {
- Trs[i].style.display = "None"; //Trs[i obtained here] is a DOM object instead of a jquery object, so you cannot use the Hide () method directly
- }
It's so simple. If it is to be displayed, change the corresponding method to show () or display property to "" to
Practical application:
Description: By default, only the row with the corresponding page name is displayed, and when the radio button is clicked, a different row is displayed.
HTML code
- < tr >
- < td class = "Tr_title_edit" > label for = "F_navname" > corresponding page link < font color = "red" > * </ font > </ label > </ TD >
- < td Class = "Tr_content_edit" >
- < input type = "Radio" id =" F_inner " name = "f_navstate" value =" 1 " checked =" checked " /> < label for = "F_inner" > internal link </ label >
- < input type="Radio" id="F_outer" name="F_navstate" value= "2" /> < label for ="F_outer"> External links </label>< /TD>
- </ TR >
- < TR id="il" style="Display:block">
- < TD class="Tr_title_edit"><label for =" F_pagename "> corresponding page name </label></TD >
- < TD class="Tr_content_edit"><Select name=' F_pageid ' id="F_pageid">
- < option Value=""></option>
- < option Value=""> news </option>
- < option Value=""> notification </option>
- </ Select > </ TD >
- </ TR >
- < TR id="ol" style="Display:none">
- < td class = "Tr_title_edit" > label for = "F_navname" > External links </ label > </ TD >
- < td Class = "Tr_content_edit" > < input type = " Text " class =" Inputline " < span class= "attribute" >size = "all" id = "F_outsidelink" name =< Span class= "Attribute-value" > "F_outsidelink" /> </ td >
- </ TR >
Hidden and displayed by ID control are as follows:
JS Code
- $ ("input[name= ' f_navstate ']"). Click (function() {
- //if ($ ("Input[name= ' f_navstate ')"). attr ("checked") ==true) {
- $ ("input[name= ' f_navstate ')"). each (function(i) {
- if (this. checked) {
- var f_navstate = $ ("input[name= ' f_navstate ')") [I].value; //Get the value of the Radio box
- if (f_navstate==1) {
- //alert (123);
- $ ("#il"). Show ();
- $ ("#ol"). Hide ();
- }Else{
- //alert (456);
- $ ("#ol"). Show ();
- $ ("#il"). Hide ();
- }
- }
- });
- //}
- });