这段代码有什么问题?当我将第一个选择更改为国际时,它会禁用第二个选择。但是当我选择“本地”时,它不会启用第二个选择
<script type="text/javascript">
function changetextbox()
{
if (document.getElementById("LocalOrInternations").value == "International") {
document.getElementById("NormalOrPaper").disabled='true';
}
else
document.getElementById("NormalOrPaper").disabled='false';
}
</script>
<span class="input-group-addon" id="basic-addon1">Local Or International</span>
<select name="LocalOrInternations" id="LocalOrInternations" onChange="changetextbox();" class="form-control">
<option value="Local">Local</option>
<option value="International">International</option>
</select>
<span class="input-group-addon" id="basic-addon1">Normal Or Paper Seminar></span>
<select name="NormalOrPaper" id="NormalOrPaper" class="form-control">
<option value="Normal">Normal</option>
<option value="Seminar">Seminar</option>
</select>
最佳答案
'false'
和 'true'
是字符串。当强制转换为 bool 值时,它们都是 true
(因为任何非空白的字符串都是“truthy”。)您需要实际的 bool 值 false
和 true
(无引号)。
if (document.getElementById("LocalOrInternations").value == "International") {
document.getElementById("NormalOrPaper").disabled = true;
// -------------------------------------------------^^^^
}
else {
document.getElementById("NormalOrPaper").disabled = false;
// -------------------------------------------------^^^^^
}
<小时/>
旁注:我建议与您的 {}
保持一致。要么将它们包含在单个语句中(就像您对 if
所做的那样),要么不包含它们(就像您对 else
所做的那样),但有时不要这样做 将它们包含在单个语句周围,而不是其他时间。
关于javascript - 为什么禁用 select html 后无法启用它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43581844/