简体   繁体   English

在表中,将属性添加到列中包含包含特定文本的单元格的单元格

[英]In a table, add property to a cell in a column which include a cell containing a specific text

I have a table as shown: 我有一张桌子如图所示:

 <table border="1" cellpadding="1" cellspacing="1" class="td1166"> <tbody> <tr> <td>Number</td> <td>A</td> <td>B</td> //Assume that this cell indicate the column I need to select <td>C</td> <td>D</td> </tr> <tr> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td></td> <td></td> //So the last cell in the 'A' column is the one I want to add property, and A is known. <td></td> <td></td> </tr> </tbody> </table> 

All the need I have presented in the code. 我在代码中提出的所有需求。 I was trying using jQuery but I have no idea how to select as such. 我正在尝试使用jQuery,但我不知道如何选择。 Hope your kind help! 希望你的帮助!

You can try something like this, note: this will only work for the first and last rows, you will need different selectors if you have different rows 您可以尝试这样的事情,注意:这只适用于第一行和最后一行,如果您有不同的行,则需要不同的选择器

 $('tr:first td').each(function(i,v){ if($(this).text() == "B") { var index = $(v).index();//get the index of the colomn $('tr:last td').eq(index).css('color','red');//select the element } }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table border="1" cellpadding="1" cellspacing="1" class="td1166"> <tbody> <tr> <td>Number</td> <td>A</td> <td>B</td> <!--//Assume that this cell indicate the column I need to select--> <td>C</td> <td>D</td> </tr> <tr> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td></td> <td>here</td><!-- //So the last cell in the 'A' column is the one I want to add property, and A is known.--> <td></td> <td></td> </tr> </tbody> 

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

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