![](/img/trans.png)
[英]How to find row index for dynamic table and on basis of that get column text
[英]How to find the text in a table row/table data
我正在嘗試使用“ 24hrs”類更改表格行中文本的顏色。 我使用jquery來查找文本,但我只是無法弄清楚。
這是我正在使用的桌子
<table class="table" id="characters-table">
<thead>
<tr>
<th>Logo</th>
<th>Abbreviation</th>
<th>Coin</th>
<th>Price</th>
<th>Market Cap</th>
<th>24hr</th>
<th>More info</th>
</tr>
</thead>
<tbody>
<template id="all-characters-template">
{{#Data}}
<tr>
<td><img class="img-coin" src="https://www.cryptocompare.com{{CoinInfo.ImageUrl}}"/></td>
<td class="character-id">{{CoinInfo.Name}}</td>
<td>{{CoinInfo.FullName}}</td>
<td>{{DISPLAY.EUR.PRICE}}</td>
<td>{{RAW.EUR.MKTCAP}}</td>
<td class="24hrs">{{DISPLAY.EUR.CHANGEPCT24HOUR}}</td>
<td><button class="btn btn-info character-info-btn" data-toggle="modal" data-target="#myModal">More Info</button></td>
</tr>
{{/Data}}
</template>
我試過了,但找不到任何東西
console.log($("#all-characters-template").closest("tr").find(".24hrs").text());
提前致謝
如前所述,您嘗試使用模板引擎的ID,而不是呈現的html元素的ID。 因此,請嘗試以下操作:
$('#characters-table tbody .24hrs').css('color', 'red');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.