1

我有下面的代码。

2 个单选按钮,选中时启用+勾选其复选框,单击另一个单选按钮时禁用+取消勾选它们。

该代码作为 HTA 可以正常工作,但不能作为 HTML 正常工作。知道最终的应用程序将是 HTA,我是否需要担心代码不能在 HTML 中完全运行?

非常感谢。

<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 id="TerminateP1" name="TerminateP1" value="IN">Terminate AD account<br>
        <input type="checkbox" disabled id="MailboxAccessP1" name="MailboxAccessP1" value="IN">Grant mailbox access to manager<br>
    </td>
    <td><font size=2>
        <input type="checkbox" disabled id="TerminateP2" name="TerminateP2" value="IN">Fully terminate AD account<br>
        <input type="checkbox" disabled id="DisableMailboxP2" name="DisableMailboxP2" value="IN">Disable mailbox<br>
    </td>
</tr>
</form>

<script type="text/javascript">
function checkbox(val)
    {
        document.phaseform.TerminateP1.setAttribute("disabled",1) 
        document.phaseform.MailboxAccessP1.setAttribute("disabled",1)
        document.phaseform.TerminateP2.setAttribute("disabled",1) 
        document.phaseform.DisableMailboxP2.setAttribute("disabled",1)
        document.phaseform.TerminateP1.setAttribute("checked",0)
        document.phaseform.MailboxAccessP1.setAttribute("checked",0)
        document.phaseform.TerminateP2.setAttribute("checked",0)
        document.phaseform.DisableMailboxP2.setAttribute("checked",0)

        if(val)
        {
            document.phaseform.TerminateP2.removeAttribute("disabled",val) 
            document.phaseform.DisableMailboxP2.removeAttribute("disabled",val)
            document.phaseform.TerminateP2.setAttribute("checked",1)
            document.phaseform.DisableMailboxP2.setAttribute("checked",1)
            }
        else
        {
            document.phaseform.TerminateP1.removeAttribute("disabled",val)
            document.phaseform.MailboxAccessP1.removeAttribute("disabled",val)
            document.phaseform.TerminateP1.setAttribute("checked",1)
            document.phaseform.MailboxAccessP1.setAttribute("checked",1)
        }
    }
</script>
4

1 回答 1

0

尝试

function checkbox(val) {
    var isone = !!val, istwo = !val;
    document.phaseform.TerminateP1.disabled = isone;
    document.phaseform.MailboxAccessP1.disabled = isone;
    document.phaseform.TerminateP2.disabled = istwo;
    document.phaseform.DisableMailboxP2.disabled = istwo;
    document.phaseform.TerminateP1.checked = !isone;
    document.phaseform.MailboxAccessP1.checked = !isone;
    document.phaseform.TerminateP2.checked = !istwo;
    document.phaseform.DisableMailboxP2.checked = !istwo;
}

演示:小提琴

于 2013-05-17T15:42:10.150 回答