Изменение цвета ячейки, если в ней определенный цвет.
Всем привет! Начинаю только изучать Java.
Есть задача - менять цвет ячейки d nf,kbwt, если в ней определенный текст. Пробую делать таким образом: $('tr').each(function(){ $(this).find('td').each(function(){ if ($(this).html("Waiting")) { $(this).parent('tr').addClass('empty'); return false; } }); }); Но ничего не получается. Сама строка таблицы <tr class="history__row"> <td class="history__cell">94OX5DPJ8L</td> <td class="history__cell">2023-02-06</td> <td class="history__cell">add</td> <td class="history__cell">1000</td> <td class="history__cell">ultrapays</td> <td class="history__cell"> Waiting </td> </tr> Может проблема, что перед словом Waiting непонятное количество символов вставлено? |
royko666,
надо получить текст и проверить наличие контрольного слова в этом тексте. в вашем коде этого нет. |
royko666,
$('tr:contains("Waiting")').addClass("empty"); |
Цитата:
Цитата:
Цитата:
|
Ячейки в строке
|
Ваш код, к сожалению, не срабатывает.
Я пока сделал подсветку строки таким образом $('tr:has(td:contains("Waiting"))').addClass("empty1"); $('tr:has(td:contains("Success"))').addClass("empty"); http://joxi.ru/KAxx4BpiV3MxjA |
Цитата:
[html run] ... минимальный код страницы с вашей проблемой [/html] О том, как вставить в сообщение исполняемый javascript и html-код, а также о дополнительных возможностях форматирования - читайте http://javascript.ru/formatting. <!DOCTYPE html> <html> <head> <title>Untitled</title> <meta charset="utf-8"> <style type="text/css"> tr.empty td{ background-color: #FF00FF; color: #FFFFFF; } </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <script> $(function() { $('tr:contains("Waiting"),tr:contains("Success")').addClass("empty"); }); </script> </head> <body> <table> <tr class="history__row"> <td class="history__cell">94OX5DPJ8L</td> <td class="history__cell">2023-02-06</td> <td class="history__cell">add</td> <td class="history__cell">1000</td> <td class="history__cell">ultrapays</td> <td class="history__cell"> Waiting </td> </tr> <tr class="history__row"> <td class="history__cell">94OX5DPJ8L</td> <td class="history__cell">2023-02-06</td> <td class="history__cell">add</td> <td class="history__cell">1000</td> <td class="history__cell">ultrapays</td> <td class="history__cell"> test </td> </tr> <tr class="history__row"> <td class="history__cell">94OX5DPJ8L</td> <td class="history__cell">2023-02-06</td> <td class="history__cell">add</td> <td class="history__cell">1000</td> <td class="history__cell">ultrapays</td> <td class="history__cell"> Success </td> </tr> </table> </body> </html> |
Часовой пояс GMT +3, время: 01:26. |