gpt4 book ai didi

管理(禁用和选中)某些复选框的 Javascript 函数

转载 作者:行者123 更新时间:2023-11-30 18:19:11 26 4
gpt4 key购买 nike

我对这段简单的 Javascript 代码有疑问:

function select_checkbox(i)
{
switch(i)
{
case 3:
if (document.upload_form.3.checked=true)
{
document.upload_form.4.checked=true;
document.upload_form.4.disabled=true;
document.upload_form.5.checked=true;
document.upload_form.5.disabled=true;
}

if (document.upload_form.3.checked=false)
{
document.upload_form.4.checked=false;
document.upload_form.4.disabled=false;
document.upload_form.5.checked=false;
document.upload_form.5.disabled=false;
}

break;

[other code]

与此 HTML 代码相关联:

     <input type="checkbox" name="3" onclick="select_checkbox(3)" />
<input type="checkbox" name="4" onclick="select_checkbox(4)" />
<input type="checkbox" name="5" onclick="select_checkbox(5)" />

我想这样做:

  • 如果我选中复选框“3”,请选中并禁用 4 和 5
  • 如果我选中复选框“4”,选中并禁用 3 + 取消选中并禁用 5
  • 如果我选中复选框“5”,取消选中并禁用 3 和 4
  • 未选中时重新启用并取消选中所有

代码的第一部分(我只报告复选框“3”的部分)工作正常,但我在通过取消选中复选框来恢复配置时遇到问题。

最佳答案

if (document.upload_form.3.checked=true)
{
}

should be replaced by

if (document.upload_form.3.checked==true)
{
}

应该是==

关于管理(禁用和选中)某些复选框的 Javascript 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12502553/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com