使用普通的JavaScript,試試這個
HTML部分
<select name="comment" id="combo" onChange="check();">
<option value="">Choose One</option>
<option value="Good">Good</option>
<option value="Others">Others</option>
</select>
<input type = "text" id ="dummyText" visible="false" style="visibility:hidden"/>
的Javascript部分
function check() {
var el = document.getElementById("combo");
var str = el.options[el.selectedIndex].text;
if(str == "Others") {
show();
}else {
hide();
}
}
function hide(){
document.getElementById('dummyText').style.visibility='hidden';
}
function show(){
document.getElementById('dummyText').style.visibility='visible';
}
檢查JSFIDDLE