单选按钮启用多个复选框

时间:2013-05-15 23:21:12

标签: javascript html button checkbox radio

我有以下代码。

第1阶段单选按钮必须启用它下方的2个复选框,并为第2阶段单选按钮启用相同的功能。

如果选择了其他单选按钮,则必须再次禁用复选框。

我已经有50%的想法正在运作,但也不知道如何为第2阶段做到这一点。

以下是我的代码。我的JavaScript知识非常差。提前谢谢!!

<html>
<head>
</head>
</body>
<table border=1>
<tr>
    <td>
        <form name="phaseform" action=""><font size=2>
        <input type="radio" name="phase" value="1" id="phase" onclick="checkbox(0)" />
            <label for="phase1">Phase 1</label>
    </td>
    <td><font size=2>
        <input type="radio" name="phase" value="2" id="phase" onclick="checkbox(1)" />
            <label for="phase2">Phase 2 (after 17 days)</label>
    </td>
</tr>
<tr>
    <td><font size=2>
        <input type="checkbox" disabled checked id="TerminateP1" name="TerminateP1" value="IN">Terminate AD account<br>
        <input type="checkbox" disabled checked id="MailboxAccessP1" name="MailboxAccessP1" value="IN">Grant mailbox access to manager<br>
    </td>
    <td><font size=2>
        <input type="checkbox" disabled checked id="TerminateP2" name="TerminateP2" value="IN">Fully terminate AD account<br>
        <input type="checkbox" disabled checked id="DisableMailboxP2" name="DisableMailboxP2" value="IN">Disable mailbox<br>
    </td>
</tr>
</form>

<script type="text/javascript">
        function checkbox(val)
        {
            if(val)
        document.phaseform.TerminateP1.setAttribute("disabled",val) 
        else
        document.phaseform.TerminateP1.removeAttribute("disabled",val)
            if(val)
        document.phaseform.MailboxAccessP1.setAttribute("disabled",val)
        else
        document.phaseform.MailboxAccessP1.removeAttribute("disabled",val)
        }
</script>

</table>
</body>
<html>

2 个答案:

答案 0 :(得分:0)

function checkbox(val)
    {
        document.phaseform.TerminateP1.setAttribute("disabled",val) 
        document.phaseform.MailboxAccessP1.setAttribute("disabled",val)
        document.phaseform.TerminateP2.setAttribute("disabled",val) 
        document.phaseform.DisableMailboxP2.setAttribute("disabled",val)
        if(val)
        {
            document.phaseform.TerminateP2.removeAttribute("disabled",val) 
            document.phaseform.DisableMailboxP2.removeAttribute("disabled",val)
        }
        else
        {
            document.phaseform.TerminateP1.removeAttribute("disabled",val)
            document.phaseform.MailboxAccessP1.removeAttribute("disabled",val)
        }
    }

答案 1 :(得分:0)

删除了表单,条带Tyler的代码,但它在GTA中无法正常工作。有人可以告诉我,以下代码是否可能导致任何未来的问题?

function checkbox(val)
{
    TerminateP1.setAttribute("disabled",1) 
    MailboxAccessP1.setAttribute("disabled",1)
    TerminateP2.setAttribute("disabled",1) 
    DisableMailboxP2.setAttribute("disabled",1)
    if(val)
    {
        TerminateP2.removeAttribute("disabled") 
        DisableMailboxP2.removeAttribute("disabled")
    }
    else
    {
        TerminateP1.removeAttribute("disabled")
        MailboxAccessP1.removeAttribute("disabled")
    }
}