简体   繁体   中英

Hide image from the table header using jquery

I have a table header as

<table class="tablestyle" id="tabHistory">
  <tr>
    <th style="min-width:15%;" onclick="javascript:doSort('0', 'Test Name');"> name</th>
    <th style="min-width:18%;" onclick="javascript:doSort('1', 'platform');">Plat</th>
    <th style="min-width:20%;" onclick="javascript:doSort('2', 'Test Server');"> Server</th>   
    <th style="width:3%;"></th>
    <tr>
</table>

code

function doSort(index, column) {
  var sortIndex = 'i' + index;
  sortOrder[sortIndex] = (sortOrder[sortIndex] == "asc") ? "desc" : "asc";


  var options = {"sortby":column, "order":sortOrder[sortIndex]};
  displayHistory(options, function() {
    var bgImg = (sortOrder[sortIndex] == "asc") ? "./images/asc.gif" : "./images/desc.gif";
    $("#tabHistory th").eq(index).css({
        "background-image": "url(" + bgImg + ")"
    });
  });
}

Here in the table head showing images in every header. I want to show images only in name and server headers not in plat header. How can i hide the image from the plat header?

You can use .eq() selector:

$("#tabHistory th:eq(0),#tabHistory th:eq(2)").css({
    "background-image": "url(" + bgImg + ")"
});

You can use:

$("#tabHistory th").eq(1).css("background-image", "none");

Working Example

另外,您也可以从Plat th省略背景图像,如下所示:

$( "#tabHistory  tr  th:contains('Plat')" ).css( "background-image", "" );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM