簡體   English   中英

如何更改所有td的值:nth-​​of-type(4)

[英]How to change values for all td:nth-of-type(4)

我正在嘗試更改第4列的值,表示td:nth-​​of-type(4),新值為“R $ 0”。 我只需要那些已取消狀態的訂單。 最后一列是td:nth-​​of-type(9),我也有一個帶類的跨度。

這是一張帶有表格的PrtSc https://i.gyazo.com/91a4cc3b38e71ce73a5ebfc809a692d6.png

最后一列td代碼<td><span class="status-cancelled">Cancelled</span></td>

嘗試這個。

$(document).ready(function(){
   $rows=$('.table tbody tr');
   $rows.each(function(){
      status=$(this).children().last().text();
      if(status=='Cancelled'){
         $(this).children().eq(3).text('R$0');
      }
   });
});

你真的可以不用jQuery做到這一點?

rows = document.querySelectorAll(".table tbody tr");
Object.keys(rows).forEach(function (key){
        if (rows[key].lastElementChild.innerText == "Cancelled") {
        rows[key].children[3].innerText = 'R$0';
    }
});

暫無
暫無

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

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