2011-01-27 28 views
0

嘿,我有一個下拉框在HTML中完成,我只是想知道是否有可能有2個單獨的文本框出現時,特定的下拉項目被選中。 所以有輸入框出現DropDown選擇HTML/Javascript

下拉 - 第1項 - 項目2 - 3項

如果第3項被選中,那麼

文本框中輸入1次出現 - 輸入文本框2出現

謝謝你們

回答

2
<select id='combo'> 
    <option>...</option> 
</select> 
<input id='text1' style='display: none'/> 
<input id='text2' style='display: none'/> 
<script> 
// Disclaimer: using a library (jquery, ext-core, prototype) to bind events and change 
// styles is safer across browsers 
document.getElementById('combo').onchange = function() { 
    var display = this.selectedIndex == 2 ? "inline" : "none"; 
    document.getElementById('text1').style.display = display; 
    document.getElementById('text2').style.display = display; 
} 
</script> 
+0

謝謝,太棒了! – 2011-01-27 23:07:12