我很难根据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