我有以下代码。
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>
答案 0 :(得分: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;
}
演示:Fiddle