简体   繁体   English

JS:更改特定列值的行背景色

[英]JS: Change row background color on specific column value

I am working on this table that as to be managed by the client. 我正在处理此 ,该由客户端管理。 I want to know if is possible to change the color of the entire row when in the "Status" column he writes the word "vermietet". 我想知道是否有可能在“状态”栏中写“ vermietet”一词时更改整个行的颜色。

In this case when the client write "vermietet" the rows that contains that word change background color in orange. 在这种情况下,当客户端写“ vermietet”时,包含该单词的行将变为橙色。

Any JS tips? 有任何JS技巧吗?

Thanks in adivce. 非常感谢。 EDIT: 编辑:

I tried this 我试过了

<script>
    jQuery(document).ready(function($){
$(document.body)var cols = document.getElementsByClassName('column-10');

for (var i = 0; i < cols.length; ++i) {
 var col = cols[i];

 if (col.innerHTML === 'vermietet') {
   var parent = col;

   while((parent = parent.parentElement).tagName !== 'TR');

   var found = parent.childNodes;

   for (var j = 0; j < found.length; ++j) {
     var td = found[j];

     if (td.tagName === 'TD') {
       td.style.backgroundColor = 'orange';
     }
   }
 }
 } 
 });
</script>

Pure JS solution: 纯JS解决方案:

    var cols = document.getElementsByClassName('column-10');

    for (var i = 0; i < cols.length; ++i) {
     var col = cols[i];

     if (col.innerHTML === 'vermietet') {
       var parent = col;

       while((parent = parent.parentElement).tagName !== 'TR');

       var found = parent.childNodes;

       for (var j = 0; j < found.length; ++j) {
         var td = found[j];

         if (td.tagName === 'TD') {
           td.style.backgroundColor = 'orange';
         }
       }
     }
   }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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