我有一个复选框列表,我需要实现检查取消选中功能,如。当某人点击Όχι(无)时,所有复选框都将取消选中。
<TABLE id=ctl00_m_g_0a9e1440_6a3d_47b2_9ccb_dd6176913570_ctl00_ddlSpeakForeignLanguages class=ms-authoringcontrols border=0>
<TBODY>
<TR>
<TD vAlign=top><INPUT style="PADDING-LEFT: 5px" id=ctl00_m_g_0a9e1440_6a3d_47b2_9ccb_dd6176913570_ctl00_ddlSpeakForeignLanguages_0 CHECKED type=checkbox name=ctl00$m$g_0a9e1440_6a3d_47b2_9ccb_dd6176913570$ctl00$ddlSpeakForeignLanguages$0></TD>
<TD><LABEL for=ctl00_m_g_0a9e1440_6a3d_47b2_9ccb_dd6176913570_ctl00_ddlSpeakForeignLanguages_0>Όχι</LABEL></TD>
<TD vAlign=top><INPUT style="PADDING-LEFT: 5px" id=ctl00_m_g_0a9e1440_6a3d_47b2_9ccb_dd6176913570_ctl00_ddlSpeakForeignLanguages_4 type=checkbox name=ctl00$m$g_0a9e1440_6a3d_47b2_9ccb_dd6176913570$ctl00$ddlSpeakForeignLanguages$4></TD>
<TD><LABEL for=ctl00_m_g_0a9e1440_6a3d_47b2_9ccb_dd6176913570_ctl00_ddlSpeakForeignLanguages_4>Αλβανικά</LABEL></TD>
<TD vAlign=top><INPUT style="PADDING-LEFT: 5px" id=ctl00_m_g_0a9e1440_6a3d_47b2_9ccb_dd6176913570_ctl00_ddlSpeakForeignLanguages_7 type=checkbox name=ctl00$m$g_0a9e1440_6a3d_47b2_9ccb_dd6176913570$ctl00$ddlSpeakForeignLanguages$7></TD>
<TD><LABEL for=ctl00_m_g_0a9e1440_6a3d_47b2_9ccb_dd6176913570_ctl00_ddlSpeakForeignLanguages_7>Ισπανικά</LABEL></TD></TR>
<TR>
<TD vAlign=top><INPUT style="PADDING-LEFT: 5px" id=ctl00_m_g_0a9e1440_6a3d_47b2_9ccb_dd6176913570_ctl00_ddlSpeakForeignLanguages_1 type=checkbox name=ctl00$m$g_0a9e1440_6a3d_47b2_9ccb_dd6176913570$ctl00$ddlSpeakForeignLanguages$1></TD>
<TD><LABEL for=ctl00_m_g_0a9e1440_6a3d_47b2_9ccb_dd6176913570_ctl00_ddlSpeakForeignLanguages_1>Αγγλικά</LABEL></TD>
<TD vAlign=top><INPUT style="PADDING-LEFT: 5px" id=ctl00_m_g_0a9e1440_6a3d_47b2_9ccb_dd6176913570_ctl00_ddlSpeakForeignLanguages_5 type=checkbox name=ctl00$m$g_0a9e1440_6a3d_47b2_9ccb_dd6176913570$ctl00$ddlSpeakForeignLanguages$5></TD>
<TD><LABEL for=ctl00_m_g_0a9e1440_6a3d_47b2_9ccb_dd6176913570_ctl00_ddlSpeakForeignLanguages_5>Ρώσικα</LABEL></TD>
<TD vAlign=top><INPUT style="PADDING-LEFT: 5px" id=ctl00_m_g_0a9e1440_6a3d_47b2_9ccb_dd6176913570_ctl00_ddlSpeakForeignLanguages_8 type=checkbox name=ctl00$m$g_0a9e1440_6a3d_47b2_9ccb_dd6176913570$ctl00$ddlSpeakForeignLanguages$8></TD>
<TD><LABEL for=ctl00_m_g_0a9e1440_6a3d_47b2_9ccb_dd6176913570_ctl00_ddlSpeakForeignLanguages_8>Ιταλικά</LABEL></TD></TR>
<TR>
<TD vAlign=top><INPUT style="PADDING-LEFT: 5px" id=ctl00_m_g_0a9e1440_6a3d_47b2_9ccb_dd6176913570_ctl00_ddlSpeakForeignLanguages_2 type=checkbox name=ctl00$m$g_0a9e1440_6a3d_47b2_9ccb_dd6176913570$ctl00$ddlSpeakForeignLanguages$2></TD>
<TD><LABEL for=ctl00_m_g_0a9e1440_6a3d_47b2_9ccb_dd6176913570_ctl00_ddlSpeakForeignLanguages_2>Γαλλικά</LABEL></TD>
<TD vAlign=top><INPUT style="PADDING-LEFT: 5px" id=ctl00_m_g_0a9e1440_6a3d_47b2_9ccb_dd6176913570_ctl00_ddlSpeakForeignLanguages_6 type=checkbox name=ctl00$m$g_0a9e1440_6a3d_47b2_9ccb_dd6176913570$ctl00$ddlSpeakForeignLanguages$6></TD>
<TD><LABEL for=ctl00_m_g_0a9e1440_6a3d_47b2_9ccb_dd6176913570_ctl00_ddlSpeakForeignLanguages_6>Ουκρανικά</LABEL></TD>
<TD vAlign=top><INPUT style="PADDING-LEFT: 5px" id=ctl00_m_g_0a9e1440_6a3d_47b2_9ccb_dd6176913570_ctl00_ddlSpeakForeignLanguages_9 type=checkbox name=ctl00$m$g_0a9e1440_6a3d_47b2_9ccb_dd6176913570$ctl00$ddlSpeakForeignLanguages$9></TD>
<TD><LABEL for=ctl00_m_g_0a9e1440_6a3d_47b2_9ccb_dd6176913570_ctl00_ddlSpeakForeignLanguages_9>Τούρκικα</LABEL></TD></TR>
<TR>
<TD vAlign=top><INPUT style="PADDING-LEFT: 5px" id=ctl00_m_g_0a9e1440_6a3d_47b2_9ccb_dd6176913570_ctl00_ddlSpeakForeignLanguages_3 type=checkbox name=ctl00$m$g_0a9e1440_6a3d_47b2_9ccb_dd6176913570$ctl00$ddlSpeakForeignLanguages$3></TD>
<TD><LABEL for=ctl00_m_g_0a9e1440_6a3d_47b2_9ccb_dd6176913570_ctl00_ddlSpeakForeignLanguages_3>Γερμανικά</LABEL></TD>
<TD vAlign=top></TD>
<TD vAlign=top></TD></TR></TBODY>
</TABLE>
答案 0 :(得分:1)
我认为您正在寻找的是:
$('table :checkbox:first').change(function() {
if(this.checked)
$('table :checkbox:gt(0)').attr('checked', false);
});
$('table :checkbox').change(function() {
$('table :checkbox:first')
.attr('checked', $('table :checkbox:gt(0):checked').length == 0);
});
You can give it a try here,它有以下行为:
这应该确保正确的输入并且相当直观,给它一个镜头看看你喜欢它。