![](/img/trans.png)
[英]Angular: How do I get a column in a table with a dropdown in each cell and set different values in each of these dropdowns?
[英]How do I replace table cell values from a dropdown?
我需要“按摩” HTML表。
在頁面上有一個下拉列表:
<SELECT CLASS='slctor' size='1' NAME='KEYVAL' ID='KEYVAL' >
<OPTION VALUE='{*}'>*
</OPTION>
<OPTION value='10'>green
</OPTION>
<OPTION value='20'>green
</OPTION>
<OPTION value='30'>green
</OPTION>
<OPTION value='40'>yellow
</OPTION>
<OPTION value='90'>red
</OPTION>
</SELECT>
我還有一個表,其中包含“人/年”和每對值:
<table>
<tr>
<td></td>
<td>2001</td>
<td>2002</td>
<td>2003</td>
</tr>
<tr>
<td>JOE</td>
<td>10</td>
<td>30</td>
<td>90</td>
</tr><tr>
<td>BETTY</td>
<td>20</td>
<td>20</td>
<td>40</td>
</tr>
</table>
我想使用jQuery從下拉列表值“解析”每個單元格值,返回標簽,並替換單元格內容(或背景顏色)。
我可以進行基本操作,就像在實際的DOM操作中一樣,但是實際上我需要以有效的方式進行查找的幫助。
Try this:
$(".slctor").change(function(){
var selectedVal=$(this).val();
$('table').find('td').filter(function(){return $(this).text() ==selectedVal}).css("background-color","red");
//or
$('table').find('td').filter(function(){return $(this).text() ==selectedVal}).text("New Text");
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.