簡體   English   中英

如何<a>使用jQuery在表單元格中</a>更改錨<a>樣式</a>

[英]How to change anchor <a> style when it's in table cell using jquery

我有以下問題需要更改使用jQuery在表格單元格中的樣式。 該更改取決於其他單元格中的值。 我有下表:

                             <table id="table">
                                <tr>
                                    <td>
                                        <a href="www.google.pl">YYYYYYYYY</a></td>
                                    <td>HHHHHHH<td>
                                </tr>
                                <tr>
                                    <td>Jedi Armor1</td>
                                    <td>HHHHHHH</td>
                                </tr>
                                <tr>
                                    <td>Jedi Armor2</td>
                                    <td>HHHHHHH</td>
                                </tr>
                            </table>

jQuery方法:

            $(document).ready(function() {

                $('#table tr td').each(function(){
                     var textValue = $(this).text();
                        if(textValue == 'HHHHHHH'){
                        // add css class or any manipulation to your dom.
                    $(this).parent().css('color','red');
                    $(this).parent().children('td a').css('color','red');
                    };
                });

            // koniec funkcji hover
        });

問題是如何改變風格?

如果您更改要find children ,則您的代碼將起作用。

看到這個小提琴演示

children()不能向下看2級

更改:

$(this).parent().children('td a')

$(this).parent().find('a');

但最簡單的方法是將一個類添加到行中,然后使用css調整整個行的樣式。 與撤消內聯CSS相比,切換類通常更容易

$(this).parent().addClass('has_H');

CSS

tr.has_H, tr.has_H a{
    color:red;
}

暫無
暫無

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

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