- 現在的表是動態的,所以很多行能來,但下拉是靜態
- 下拉第2個和第3個值蘋果和Orange只能來表第2列和下拉4日和5日值「食」和「爛」只可能在第4列
- 所有的代碼應該在功能viewChange()現在
在當Apple
被選中所有具有第二列值的行與蘋果將顯示等等。隱藏和顯示基於一個下拉的值表的行 - jQuery的
選擇 - 全部將再次顯示整個表格
如何編寫函數?
function ViewChange()
{
var selectedViewName = $('#dropDown :selected').val();
switch (selectedViewName)
{
case("1"):
selectedViewName="ALL";
break;
case("2"):
selectedViewName = "Apple";
break;
case("3"):
selectedViewName = "Orange";
break;
case("4"):
selectedViewName = "Fresh";
break
case("5"):
selectedViewName = "Rotten";
break
}
<select id="dropDown" onchange="ViewChange()"><option value="1">All</option>
<option value="2">Apple</option>
<option value="3">Orange</option>
<option value="4">Fresh</option>
<option value="5">Rotten</option>
</select>
<table id="tableID">
<thead>
<tr>
<th>Name</th>
<th>Fruit type</th>
<th>place</th>
<th>state</th>
</tr>
</thead>
<tbody>
<tr>
<td>salim groceries</td>
<td>apple</td>
<td>nagpur</td>
<td>fresh</td>
</tr>
<tr>
<td>monalisa groceries</td>
<td>Apple</td>
<td>Belapur</td>
<td>Rotten</td>
</tr>
<tr>
<td>taj groceries</td>
<td>Orange</td>
<td>Nasik</td>
<td>Fresh</td>
</tr>
<tr>
<td>suraj groceries</td>
<td>Orange</td>
<td>Goa</td>
<td>Rotten</td>
</tr>
</tbody>
</table>
請看看這個小提琴https://jsfiddle.net/shaswatatripathy/pvxmrL2n/8/
你有一個關於這個代碼的問題?我只能看到你的要求列表 –
添加了問題 – tripathy
看看這裏http:// stackoverflow。com/questions/35632168/i-want-to-toggle-the-table-rows-filter-based-on-the-text-from-buttons/35639792#35639792 – Alexis