我很難根據select
標記中的選定項目更改元素的類別。這是我的代碼:使用javascript更改元素的類別
<table>
<tr>
<select onchange="wow(this.value)">
<option value="a">a</option>
<option value="b">b</option>
</select>
</tr>
<tr id="x" class="show">
x
</tr>
</table>
<script>
function wow(value){
switch(value){
case "a": document.getElementById("x").className = "show"; break;
case "b": document.getElementById("x").className = "hide"; break;
}
}
</script>
<style>
.show{
display:inline-block;
}
.hide{
display:none;
}
</style>
我這裏看不到任何問題。我也試過setAttribute("class", "show")
,但不起作用。
@GlennFerrieLive這是一個jQuery的例子。 – Hamish 2013-03-11 03:53:03
你錯過了交換機的'case'部分。 – j08691 2013-03-11 03:54:41