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

时间:2019-06-18 03:42:58

标签: javascript html-table datatable

我正在尝试将第4列的值更改为td:nth-​​of-type(4),并使用新值“ R $ 0”。我只需要对状态已取消的订单执行此操作。最后一列是td:nth-​​of-type(9),我的班级也很长。

这是带有表https://i.gyazo.com/91a4cc3b38e71ce73a5ebfc809a692d6.png的PrtSc

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

2 个答案:

答案 0 :(得分:0)

尝试一下。

$(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');
      }
   });
});

答案 1 :(得分: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';
    }
});