Display hiding of jquery control tr

Source: Internet
Author: User

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
  1. < Table >
  2. < TR > < TD > This line does not hide </td></tr>
  3. < TR id="tr_1"><td> This line to hide </TD > </ TR >
  4. < TR id="tr_2"><td> This line to hide </ TD > </ TR >
  5. ...
  6. </ Table >

Then control explicit can be used directly

JS Code
    1. for (var i = 1; i < Tr_len; i++) { //tr_len is the number of TR to be controlled
    2. $ ("#tr_"+i). Hide ();
    3. }

The second method is to use $.each (), which needs to set the table ID as follows:

HTML code
  1. < Table id="TBL">
  2. < TR > < TD > This line does not hide </td></tr>
  3. < TR > < TD > This line to hide </td></tr>
  4. < TR > < TD > This line to hide </td></tr>
  5. ...
  6. </ Table >

Then control explicit can be used directly

JS Code
    1. $.each ($ ("#Tbl tr"), function(i) {
    2. if (i > 0) {
    3. this. style.display = ' None ';
    4. }
    5. });

The third method , through a property filter, requires that a specific attribute, such as class, be added to TR, as follows:

HTML code
  1. < Table id="TBL">
  2. < TR > < TD > This line does not hide </td></tr>
  3.     < tr > < td  class = "HID" > this line to hide </ TD > </ tr >    
  4. < TR > < TD class="hid"> This line to hide </td></ TR>
  5. ...
  6. </ Table >

Then control explicit can be used directly

JS Code
    1. var trs = $ ("tr[class= ' hid ']");
    2. for (i = 0; i < trs.length; i++) {
    3. 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
    4. }

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
  1. < tr >    
  2. < td  class = "Tr_title_edit" > label  for = "F_navname" > corresponding page link < font  color = "red" > * </ font > </ label > </ TD >   
  3. < td    Class = "Tr_content_edit" >   
  4. < input  type = "Radio"  id =" F_inner "   name = "f_navstate"  value =" 1 "  checked =" checked "  /> < label  for = "F_inner" > internal link </ label >   
  5. < input type="Radio" id="F_outer" name="F_navstate" value= "2" /> < label for ="F_outer"> External links </label>< /TD>
  6. </ TR >
  7. < TR id="il" style="Display:block">
  8. < TD class="Tr_title_edit"><label for =" F_pagename "> corresponding page name </label></TD >
  9. <  TD class="Tr_content_edit"><Select name=' F_pageid ' id="F_pageid">
  10. < option Value=""></option>
  11. < option Value=""> news </option>
  12. < option Value=""> notification </option>
  13. </ Select > </ TD >
  14. </ TR >
  15. < TR id="ol" style="Display:none">
  16. < td  class = "Tr_title_edit" > label  for = "F_navname" > External links </ label > </ TD >   
  17. < 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 >   
  18. </ TR >

Hidden and displayed by ID control are as follows:

JS Code
  1. $ ("input[name= ' f_navstate ']"). Click (function() {
  2. //if ($ ("Input[name= ' f_navstate ')"). attr ("checked") ==true) {
  3. $ ("input[name= ' f_navstate ')"). each (function(i) {
  4. if (this. checked) {
  5. var f_navstate = $ ("input[name= ' f_navstate ')") [I].value; //Get the value of the Radio box
  6. if (f_navstate==1) {
  7. //alert (123);
  8. $ ("#il"). Show ();
  9. $ ("#ol"). Hide ();
  10. }Else{
  11. //alert (456);
  12. $ ("#ol"). Show ();
  13. $ ("#il"). Hide ();
  14. }
  15. }
  16. });
  17. //}
  18. });

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.