我搜索瞭如何根據下拉列表中的選項顯示/隱藏列。我寫了這個:根據下拉列表中的選項顯示/隱藏列
function categoriesCriteres() {
var sections = document.getElementById("sections").value;
if (sections == "generaux") {
document.getElementByClassName("generaux").style.display = "block";
} else {
document.getElementByClassName("generaux").style.display = "none";
}
}
<select class="form-control" id="sections" name="sections" onchange="categoriesCriteres()">
<option value="choisir" selected disabled>Choisir</option>
<option id="generaux" value="generaux">Apports généraux</option>
<option id="mineraux" value="mineraux">Minéraux</option>
<option id="vitamines" value="vitamines">Vitamines</option>
<option id="autres" value="autres">Autres</option>
</select>
<div>
<table class="table table-striped" id="nutrition">
<thead>
<tr>
<th>Aliments</th>
<th>Poids</th>
<th class="generaux">Energie kJ</th>
<th class="generaux">Energie kcal</th>
</thead>
<tbody class="text-primary" id="myrecap">
<tr>
<td>blé</td>
<td><strong>150gr</strong></td>
<td class="generaux">energie_kJ</td>
<td class="generaux">energie_kcal</td>
</tr>
<tr>
<td>Total</td>
<td><strong>150 gr</strong></td>
</tr>
</tbody>
</table>
</div>
但是,當我在我的下拉列表中更改數值沒有發生......我不明白什麼是錯的....也許有人可以幫我嗎?
其實,事情確實發生了:你得到一個錯誤。我建議你看看那個。錯誤是沒有'document.getElementByClassName()'這樣的函數。 –
http://stackoverflow.com/questions/4398966/how-can-i-hide-select-options-with-javascript-cross-browser –
沒有'document.getElementByClassName()'它的'document.getElementsByClassName() '筆記'' – Khaleel