remove that has   and make sub header

后端 未结 1 1457
攒了一身酷
攒了一身酷 2021-01-24 16:11

am working on an application that reads data from servers that I do not have control over but I need to style the front end on this table to look like the others. the table look

1条回答
  •  暖寄归人
    2021-01-24 16:37

    I believe the following function accomplishes what you want by doing:

    1. Loop through all
    2. Get all the inside
    3. Store the at index 1 (Description)
    4. Filter the remaining collection and get the ones that just contain  
    5. If all are empty, remove them and adjust the properties of the remaining

    $(function() {
      $("table tr").each(function() {
        var tds = $(this).find("td"); //find all td
        var descriptionTD = tds.eq(1); //get the td for the description
        
        //get the remaining tds that only contain " "
        var emptytds = tds.not(descriptionTD).filter(function() {
          return $(this).html() === " ";
        });
        
        //if all the remaing tds are empty
        if (emptytds.length === tds.length - 1) {
          emptytds.remove();
          descriptionTD.prop("colspan", tds.length).prop("width", "100%");
        }
      });
    });
    
    
    Date Description 1 Result Range Comments
      Description 2      
    Date Description 3 Result Range Comments
      Description 4      

    0 讨论(0)
提交回复
热议问题