繁体   English   中英

如何在表格行/表格数据中查找文本

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM