Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/454.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将下拉菜单链接到复选框_Javascript_Jquery_Html_Html Lists - Fatal编程技术网

JavaScript将下拉菜单链接到复选框

JavaScript将下拉菜单链接到复选框,javascript,jquery,html,html-lists,Javascript,Jquery,Html,Html Lists,我正在尝试将我的HTML下拉菜单链接到我的表,该表中有复选框 此javascript函数尝试查看是否已选择“arc”值,然后禁用复选框3,该复选框显示: function showShields() { if (document.getElementById("Shield").value == ("arc") { document.getElementById("checkBox3").disabled=true; } } 这是HTML代码: <!DOCTYPE html> &

我正在尝试将我的HTML下拉菜单链接到我的表,该表中有复选框

此javascript函数尝试查看是否已选择“arc”值,然后禁用复选框3,该复选框显示:

function showShields()
{
if (document.getElementById("Shield").value == ("arc")
{
document.getElementById("checkBox3").disabled=true;
}
}
这是HTML代码:

<!DOCTYPE html>

<html>
<head>
<script src="SpiritShield.js"></script>
</head>
<body>
<p>What kind of shield are you interested in?</p>
<select id="Shield">
   <option value="arc">ARC</option>
   <option value="divine">GAS</option>
   <option value="spectral">MIG</option>
   <option value="elysian">ANY</option>
</select>
</body>
<table border="2" cellspacing="0">
<tr>
   <th>Checkbox</th>
   <th>Shield</th>
</tr>
<tr>
   <td><input type="checkbox" id="checkBox1"</td>
   <td>ARC1</td>
</tr>
<tr>
   <td><input type="checkbox" id="checkBox2"</td>
   <td>ARC2</td>
</tr>
<tr>
   <td><input type="checkbox" id="checkBox3"</td>
   <td>SPECTRAL1</td>
</tr>
<tr>
   <td><input type="checkbox" id="checkBox4"</td>
<td>SPECTRAL2</td>
</tr>
</table>

</html>

你对什么样的盾牌感兴趣

弧 煤气 米格 任何 复选框 盾
您的代码很好,尽管我注意到if条件中缺少括号:

function showShields()
{
if (document.getElementById("Shield").value == ("arc")) //your missing missing parenthesis was here
{
document.getElementById("checkBox3").disabled=true;
}
}
试试这个:

功能显示屏蔽(什么)
{
如果(what.value==(“弧”))
{
document.getElementById(“checkBox3”).checked=false;
}
}​
你对什么样的盾牌感兴趣

--- 弧 煤气 米格 任何 复选框 盾
在你的HTML中,有一些未关闭的标记。嗯,在哪里?另外,我不认为这就是我的javascript函数无法工作的原因:(Muthu是对的,您的/body标记在您的选择之后,您应该在/html之前将其移动到底部。哦,谢谢,我刚刚意识到。但是它仍然不起作用:O@Gary
标记未关闭。
标记在某个地方关闭,感谢您的回复。不幸的是,上述操作仍然无效。当我从下拉菜单中选择ARC时n菜单表中的复选框未被禁用。:(您好,谢谢您的回复。该代码只是勾选了复选框,我希望它禁用复选框,以便用户无法单击它。我已更新了代码,请再次选中它。我将您的代码解释为错误;-)好的,谢谢,但它不起作用,哈哈。你能试试js的代码看它是否起作用。所以当选择arc选项时,表格应该自动禁用复选框3。好的,我刚刚在那里试过,当我选择arc选项时,按钮是可点击的,这会发生在你身上吗?哦,别担心,我修复了它。谢谢
function showShields(what)
    {
    if (what.value == ("arc"))
        {
        document.getElementById("checkBox3").checked=false;
        }
    }​

<!DOCTYPE html>

<!DOCTYPE html>

<html>
<head>
<script src="SpiritShield.js"></script>
</head>
<body>
<p>What kind of shield are you interested in?</p>
<select id="Shield" onchange="showShields(this)">
       <option value="arc">---</option>
   <option value="arc">ARC</option>
   <option value="divine">GAS</option>
   <option value="spectral">MIG</option>
   <option value="elysian">ANY</option>
</select>
</body>
<table border="2" cellspacing="0">
<tr>
   <th>Checkbox</th>
   <th>Shield</th>
</tr>
<tr>
   <td><input type="checkbox" id="checkBox1"</td>
   <td>ARC1</td>
</tr>
<tr>
   <td><input type="checkbox" id="checkBox2"</td>
   <td>ARC2</td>
</tr>
<tr>
   <td><input type="checkbox" id="checkBox3" checked="checked"></td>
   <td>SPECTRAL1</td>
</tr>
<tr>
   <td><input type="checkbox" id="checkBox4"</td>
<td>SPECTRAL2</td>
</tr>
</table>

</html>​