Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JS脚本没有';t更改表格行背景色_Javascript_Jquery_Thymeleaf - Fatal编程技术网

Javascript JS脚本没有';t更改表格行背景色

Javascript JS脚本没有';t更改表格行背景色,javascript,jquery,thymeleaf,Javascript,Jquery,Thymeleaf,首先,我有两张桌子。单击主表上的行时,将打开一个模式窗口,其中包含辅助表。次表包含日期列。如果日期等于“1111-11-11/11:11:11”,则表示存在错误,因此,行背景颜色应切换为红色 以下是单击第一个表上的行后打开模式窗口的代码: $(document).on('click', '#main-table tbody tr', function () { var id = $(this).find("td").eq(0).text(); openPoolModal(id); });

首先,我有两张桌子。单击主表上的行时,将打开一个模式窗口,其中包含辅助表。次表包含日期列。如果日期等于
“1111-11-11/11:11:11”
,则表示存在错误,因此,行背景颜色应切换为红色

以下是单击第一个表上的行后打开模式窗口的代码:

$(document).on('click', '#main-table tbody tr', function () {
  var id = $(this).find("td").eq(0).text();
  openPoolModal(id);
});
没什么复杂的<代码>openPoolModal功能是我将日期打印到控制台并尝试更改颜色的地方

function openPoolModal(id){

$.ajax({
url: "/" + id,
success: function(data){
$("#PoolModalHolder").html(data);
$("#personalModal").modal();
$("#personalModal").modal('show');
$('#poolTable').DataTable({
        some DataTables settings;
});
}
});

$("#poolTable tr").each(function(){
  var col_val = $(this).find("td").eq(1).text();

    console.log(col_val);

      if (col_val == "1111-11-11 / 11:11:11"){
     $(this).css( "background-color", "yellow" );
  }
});
}
以及从ajax调用返回的html代码:

<div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">&times;</button>
            <h4 class="modal-title text-center" th:text="'Network: ' + ${poolHashrates[0].networkHashrate.id}">Network Id</h4>
        </div>
        <div class="modal-body">
            <div class="table-responsive">
                <table width="100%" class="table table-hover " id="poolTable">

                    <thead class="thead-inverse">
                    <tr>
                        <th class="col-md-2 text-center">Pool name</th>
                        <th class="col-md-2 text-center">Date from</th>
                        <th class="col-md-2 text-center">Hashrate [KH/s]</th>
                    </tr>
                    </thead>

                    <tbody>
                    <tr th:each="poolHashrate : ${poolHashrates}">
                        <td class="text-center" th:text="${poolHashrate.poolDef.name}"> Sample data</td>
                        <td class="text-center" th:text="${@getDataService.formatDate(poolHashrate.poolDef.dateFrom)}">Maven Street 10, Glasgow</td>
                        <td class="text-center" th:text="${@getDataService.formatHashrate(poolHashrate.hashrate)}">999-999-999</td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
…似乎不起作用,因为它不会给背景上色。

如下图所示使用

$(this).css( "background", "yellow" );

你试过调试它吗?我不是一个真正的JS开发人员,我对调试JS一无所知。
$(this).css( "background", "yellow" );