此代碼不起作用,爲什麼?Javascript隱藏顯示對象
<script>
function color(color_type){
if (color_type == 'blue'){
document.getElementById('blue').style.display = 'block';
document.getElementById('red').style.display = 'none';
}
else{
document.getElementById('blue').style.display = 'none';
document.getElementById('red').style.display = 'block';
}
}
</script>
<select onchange="color(this.value)">
<option name="choice1" value="red" >red</option>
<option name="choice2" value="blue" >blue</option>
</select>
<div id="red" style="display:none;">
<?
//
echo "<tr>
<td width='100' class='tbl'>Just ask</td>
<td width='80%' class='tbl'><input type='text' name='1' value='$n1' class='textbox' style='width: 250px'></td>
</tr>";
//
?>
</div>
<div id="blue" style="display:none;">
<?
//
echo "<tr>
<td width='100' class='tbl'>Just ask blue</td>
<td width='80%' class='tbl'><input type='text' name='2' value='$n2' class='textbox' style='width: 250px'></td>
</tr>";
//
?>
</div>
td表不隱藏,每次都顯示此表。當我選擇藍色或紅色只顯示「只問藍色」或「請問」表格時,我需要這一點。
P.S對不起我的英文不好的語言
它正常工作對我來說:http://jsfiddle.net/fkling/nTczy/。請注意'tr'元素**必須是'table'('thead','tbody','tfoot')元素的子元素,它們不能是'div'的子元素。 –
你有css嗎? –
我有檢查這個代碼工作。請刪除瀏覽器中的緩存。 – Chinmay235