首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >单选按钮和复选框javascript

单选按钮和复选框javascript
EN

Stack Overflow用户
提问于 2013-05-17 23:29:03
回答 1查看 1K关注 0票数 1

我有下面的代码。

2个单选按钮,选中时enable+tick其复选框,单击另一个单选按钮时disable+untick它们。

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

非常感谢。

代码语言:javascript
运行
复制
<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>
EN

Stack Overflow用户

回答已采纳

发布于 2013-05-17 23:42:10

试一试

代码语言:javascript
运行
复制
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;
}

演示:Fiddle

票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16612796

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档