簡體   English   中英

使用jQuery從表標題隱藏圖像

[英]Hide image from the table header using jquery

我有一個表頭

<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>

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 + ")"
    });
  });
}

表格標題中的每個標題中都顯示有圖像。 我只想在名稱和服務器頭中顯示圖像,而不在平台頭中顯示圖像。 如何隱藏平台標頭中的圖像?

您可以使用.eq()選擇器:

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

您可以使用:

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

工作實例

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM