Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/460.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么禁用select html后无法启用它?_Javascript - Fatal编程技术网

Javascript 为什么禁用select html后无法启用它?

Javascript 为什么禁用select html后无法启用它?,javascript,Javascript,这个代码怎么了?当我将“第一选择”更改为“国际”时,它将禁用第二选择。但当我选择本地时,它不会启用第二个选择 <script type="text/javascript"> function changetextbox() { if (document.getElementById("LocalOrInternations").value == "International") { document.getElementById("NormalOrPaper"

这个代码怎么了?当我将“第一选择”更改为“国际”时,它将禁用第二选择。但当我选择本地时,它不会启用第二个选择

<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”是字符串。当强制为布尔值时,它们都是真的,因为任何非空字符串都是真的。您希望实际的布尔值为false和true,不加引号

if (document.getElementById("LocalOrInternations").value == "International") {
    document.getElementById("NormalOrPaper").disabled = true;
    // -------------------------------------------------^^^^
} 
else {
    document.getElementById("NormalOrPaper").disabled = false;
    // -------------------------------------------------^^^^^
}
旁注:我建议与您的{}保持一致。可以像处理if一样在单个语句中包含它们,也可以不像处理else一样在单个语句中包含它们,但有时不要在单个语句中包含它们,其他时候不要包含。

false和true是字符串。当强制为布尔值时,它们都是真的,因为任何非空字符串都是真的。您希望实际的布尔值为false和true,不加引号

if (document.getElementById("LocalOrInternations").value == "International") {
    document.getElementById("NormalOrPaper").disabled = true;
    // -------------------------------------------------^^^^
} 
else {
    document.getElementById("NormalOrPaper").disabled = false;
    // -------------------------------------------------^^^^^
}
旁注:我建议与您的{}保持一致。可以像处理if一样在单个语句中包含它们,也可以不像处理else那样在单个语句中包含它们,但有时不要在单个语句中包含它们,其他时候不要包含它们。

您必须从布尔标记中删除'

你必须这样设置

<script type="text/javascript">
function changetextbox()
{
    if (document.getElementById("LocalOrInternations").value == "International") {
        document.getElementById("NormalOrPaper").disabled=true;
    } 
  else
     document.getElementById("NormalOrPaper").disabled=false;
}
</script>
选中此JSFIDLE:

您必须从布尔标记中删除“”

你必须这样设置

<script type="text/javascript">
function changetextbox()
{
    if (document.getElementById("LocalOrInternations").value == "International") {
        document.getElementById("NormalOrPaper").disabled=true;
    } 
  else
     document.getElementById("NormalOrPaper").disabled=false;
}
</script>
检查此JSIDLE:

这应该会有所帮助

document.getElementById("NormalOrPaper").removeAttribute('disabled');
这应该会有所帮助

document.getElementById("NormalOrPaper").removeAttribute('disabled');

.disabled=true/.disabled=false非'true'为disabled指定布尔值true/falseproperty@chiragpatel:否,当按OP原样处理属性时,将其设置为false是正确的。.disabled=true/.disabled=false非'true'为disabled指定布尔值true/falseproperty@chiragpatel:没有,在按OP原样处理属性时,将其设置为false是正确的。这确实有效,但按OP原样使用属性更干净、更简单。@T.J.Crowder-我同意,但是我现在倾向于使用removeAttribute,因为我过去在一些浏览器上遇到过问题,现在是时候提到IE了吗?@TonyDuffill:这很有趣。我在处理财产时从来没有遇到过麻烦。我在处理属性时遇到了一些问题:-@T.J.克劳德-是的,谢谢你的纠正-你显然比我更有经验。回顾我的笔记,在IE中重置属性之前,有时确实需要删除属性,可能只有7/8/9?-我猜。这是可行的,但在OP中使用属性更干净、更简单。@T.J.Crowder-我同意,但我现在倾向于使用removeAttribute,因为我过去在一些浏览器中遇到过问题,现在是时候提到IE了吗?@TonyDuffill:这很有趣。我在处理财产时从来没有遇到过麻烦。我在处理属性时遇到了一些问题:-@T.J.克劳德-是的,谢谢你的纠正-你显然比我更有经验。回顾我的笔记,在IE中重置属性之前,有时确实需要删除属性,可能只有7/8/9?-我猜。非常感谢,在这个错误中,我感觉我是在第一节编程课上。这已经发生了。@khorshid:一开始我们都是新手!:-非常感谢,在这个错误中,我感觉我是在第一节编程课上。这已经发生了。@khorshid:一开始我们都是新手!:-