我想根据组合框所选值的值设置文本框的可见性。 这是我的代码:
<table width="500" align="center">
<tr>
<td><span> Name:</span></td>
<td><input name="name" type="text" id="name" size="40" class=""/></td>
</tr>
<tr>
<td><span>Email ID:</span></td>
<td><input name="email" type="email" id="email" size="40" class=""/></td>
</tr>
<tr>
<td><span>Select:</span></td>
<td>
<select id="edition">
<option value="none" selected>----Select ----</option>
<option id="1">A</option>
<option id="2">B</option>
</select>
</td>
</tr>
<tr>
<td><span>Number of Licenses</span></td>
<td><input type="text" id="licenseNo" size="5" value="30" /></td>
</tr>
</table>
如果组合框的值为 B,我希望 licenseNo
文本框可见。我不知道该怎么做。
最佳答案
使用JS添加事件监听器:
<script type="text/javascript">
function func() {
var elem = document.getElementById("edition");
if(elem.options[elem.selectedIndex].innerHTML == "B") {
document.getElementById("licenseNo").style.display = "";
} else {
document.getElementById("licenseNo").style.display = "none";
}
}
</script>
<select id="edition" onchange="javascript:func();">
...
</select>
另外,当页面刚刚加载时,不要忘记在开始时调用 func()
。
关于php - 文本框的可见性取决于组合框的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15410341/