如何仅使用java脚本实现从复选框列表中选中的一个复选框。如何仅实现一个复选框选择功能到Chekc框列表?
下面是脚本:
<script language="javascript" type="text/javascript">
var previousCheckId;
function toggle(chkBox) {
if (chkBox.checked) {
if (previousCheckId) {
document.getElementById(previousCheckId).checked = false;
}
previousCheckId = chkBox.getAttribute('id');
}
}
</script>
这里是我的设计:
<tr>
<td class="BlackTextBold" align="right" height="25" width="32%"><div align="left"><strong>
Product :</strong><span class="top-txt"><span style="font-size: 12.0pt; font-family: Tahoma,sans-serif; color: red">*</span></span></div></td>
<td height="20" width="68%">
<asp:CheckBoxList ID="chkLst" runat="server" Font-Bold="True"
RepeatDirection="Horizontal" Width="50%">
<asp:ListItem onClick="toggle(this);" Value="EasyOFFICE">EasyOFFICE</asp:ListItem>
<asp:ListItem onClick="toggle(this);" Value="EasyVAT">EasyVAT</asp:ListItem>
</asp:CheckBoxList>
</td>
</tr>
<tr>
<td class="BlackTextBold" align="right" height="25" width="32%"><div align="left"><strong>
PC Type :</strong><span class="top-txt"><span style="font-size: 12.0pt; font-family: Tahoma,sans-serif; color: red">*</span></span></div></td>
<td height="20" width="68%">
<asp:CheckBoxList ID="chkLst" runat="server" Font-Bold="True"
RepeatDirection="Horizontal" Width="30%">
<asp:ListItem onClick="toggle(this);" Value="Server">Server</asp:ListItem>
<asp:ListItem onClick="toggle(this);" Value="LAN">LAN</asp:ListItem>
</asp:CheckBoxList>
</td>
</tr>
但是该脚本正常工作与一个复选框列表,但是当我只是想同样的事情到其他复选框列表,然后它适用于4个。
为什么又使用相同的清单?这段代码正在编译?至少更改第二个复选框列表的名称。 –