当单击父级时,我正在使用此 jquery 来选择所有子级并且它工作正常。
$(document).ready(function () {
$("div[id $= Tree_Index]").find("input[type=checkbox]:first").click(function () {
$(this).closest("div").find(':checkbox').attr('checked', this.checked);
});
});
现在,如果我有一个孩子的子孩子,我想在选择孩子时选择所有的子孩子。我怎样才能在 jquery 中实现这一点。
<div style="font-size: 11px; font-family: Tahoma; font-weight: bold; text-align: left;" class="tree" id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Index">
<table cellspacing="0" cellpadding="0" style="border-width:0;">
<tbody><tr>
<td><a href="javascript:__doPostBack('ctl00$cphMain$ctlEsnSearchByServices$Treecontrol_Left_0$Tree_Index','t1730b784-94ca-42d3-80aa-1c9c064e271c')"><img style="border-width:0;" alt="Collapse Clinics" src="/WebResource.axd?d=_533LbcrYzxclETTqT9E9lbjpoP9iiSVLn9WP908dD96sH9D2JXH4BN8Q2OdATM4TYJU67kfDSnJQpffp_ITMVu3Y839pir-IzEhB41mqu6U8EWb0&t=634604712479085897"></a></td><td class="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Index_1"><input type="checkbox" id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn0CheckBox" name="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn0CheckBox"><span id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indext0" class="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Index_0">Clinics</span></td>
</tr>
</tbody></table><table cellspacing="0" cellpadding="0" style="border-width:0;">
<tbody><tr>
<td><div style="width:20px;height:1px"></div></td><td><a href="javascript:__doPostBack('ctl00$cphMain$ctlEsnSearchByServices$Treecontrol_Left_0$Tree_Index','t1730b784-94ca-42d3-80aa-1c9c064e271c\\3f2cfef3-2466-48f7-84aa-82cd23bc3249')"><img style="border-width:0;" alt="Collapse GP Clinics" src="/WebResource.axd?d=PtoZaOE4OJ68kA17eB1Ru-nLDbZ-ilvB8z5abVJ8BfKZp0iKKZ8iPpsV8tJ5bLWmNAAyfP3gCpxQRyrUtuHqeJKGILYd8Nbb3deoYK17HD9ZYyeS0&t=634604712479085897"></a></td><td class="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Index_1"><input type="checkbox" id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn1CheckBox" name="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn1CheckBox"><span id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indext1" class="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Index_0">GP Clinics</span></td>
</tr>
</tbody></table><table cellspacing="0" cellpadding="0" style="border-width:0;">
<tbody><tr>
<td><div style="width:20px;height:1px"></div></td><td><div style="width:20px;height:1px"><img alt="" src="/WebResource.axd?d=J9BSVEmYJ2R79DzKPp_KwudhxkmRYjt31taLGpqjHFuG3gyciimdNIz2hfef3rMTcgKKF9rZcFetwoS-fvXnw3uYWh88CZ98-dNXPYEoMwTaffwZ0&t=634604712479085897"></div></td><td><img alt="" src="/WebResource.axd?d=Ptpr_s5NKQd2NhXQH_MiSClxDVR5ZHar9QZwFenhB3L_8-vIXRA_NHlxqP3iWPQWzSbDizVZ5YO8o3q4fX1XUhismQEMBdpf8AuHvaSyrvYco4WB0&t=634604712479085897"></td><td class="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Index_1"><input type="checkbox" id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn2CheckBox" name="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn2CheckBox"><span id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indext2" class="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Index_0">CDMP Participating Clinics</span></td>
</tr>
</tbody></table><table cellspacing="0" cellpadding="0" style="border-width:0;">
<tbody><tr>
<td><div style="width:20px;height:1px"></div></td><td><div style="width:20px;height:1px"><img alt="" src="/WebResource.axd?d=J9BSVEmYJ2R79DzKPp_KwudhxkmRYjt31taLGpqjHFuG3gyciimdNIz2hfef3rMTcgKKF9rZcFetwoS-fvXnw3uYWh88CZ98-dNXPYEoMwTaffwZ0&t=634604712479085897"></div></td><td><img alt="" src="/WebResource.axd?d=Ptpr_s5NKQd2NhXQH_MiSClxDVR5ZHar9QZwFenhB3L_8-vIXRA_NHlxqP3iWPQWzSbDizVZ5YO8o3q4fX1XUhismQEMBdpf8AuHvaSyrvYco4WB0&t=634604712479085897"></td><td class="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Index_1"><input type="checkbox" id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn3CheckBox" name="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn3CheckBox"><span id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indext3" class="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Index_0">CHAS Participating Clinics - Dental</span></td>
</tr>
</tbody></table><table cellspacing="0" cellpadding="0" style="border-width:0;">
<tbody><tr>
<td><div style="width:20px;height:1px"></div></td><td><div style="width:20px;height:1px"><img alt="" src="/WebResource.axd?d=J9BSVEmYJ2R79DzKPp_KwudhxkmRYjt31taLGpqjHFuG3gyciimdNIz2hfef3rMTcgKKF9rZcFetwoS-fvXnw3uYWh88CZ98-dNXPYEoMwTaffwZ0&t=634604712479085897"></div></td><td><img alt="" src="/WebResource.axd?d=Ptpr_s5NKQd2NhXQH_MiSClxDVR5ZHar9QZwFenhB3L_8-vIXRA_NHlxqP3iWPQWzSbDizVZ5YO8o3q4fX1XUhismQEMBdpf8AuHvaSyrvYco4WB0&t=634604712479085897"></td><td class="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Index_1"><input type="checkbox" id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn4CheckBox" name="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn4CheckBox"><span id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indext4" class="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Index_0">CHAS Participating Clinics – Medical</span></td>
</tr>
</tbody></table><table cellspacing="0" cellpadding="0" style="border-width:0;">
<tbody><tr>
<td><div style="width:20px;height:1px"></div></td><td><div style="width:20px;height:1px"><img alt="" src="/WebResource.axd?d=J9BSVEmYJ2R79DzKPp_KwudhxkmRYjt31taLGpqjHFuG3gyciimdNIz2hfef3rMTcgKKF9rZcFetwoS-fvXnw3uYWh88CZ98-dNXPYEoMwTaffwZ0&t=634604712479085897"></div></td><td><img alt="" src="/WebResource.axd?d=Ptpr_s5NKQd2NhXQH_MiSClxDVR5ZHar9QZwFenhB3L_8-vIXRA_NHlxqP3iWPQWzSbDizVZ5YO8o3q4fX1XUhismQEMBdpf8AuHvaSyrvYco4WB0&t=634604712479085897"></td><td class="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Index_1"><input type="checkbox" id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn5CheckBox" name="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn5CheckBox"><span id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indext5" class="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Index_0">IDAPE/ElderShield Disability Assessors</span></td>
</tr>
</tbody></table><table cellspacing="0" cellpadding="0" style="border-width:0;">
<tbody><tr>
<td><div style="width:20px;height:1px"></div></td><td><div style="width:20px;height:1px"><img alt="" src="/WebResource.axd?d=J9BSVEmYJ2R79DzKPp_KwudhxkmRYjt31taLGpqjHFuG3gyciimdNIz2hfef3rMTcgKKF9rZcFetwoS-fvXnw3uYWh88CZ98-dNXPYEoMwTaffwZ0&t=634604712479085897"></div></td><td><img alt="" src="/WebResource.axd?d=BOvsSO2B3BKMupOSRxbma89ER-i_r1FrqfnVsgVq_QiVog3IJUebdD29i4BVAo26-lbJh_BLXmsQGU_VArXhNt6ejiWJk87whzKer6ts-_kM9Vt90&t=634604712479085897"></td><td class="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Index_1"><input type="checkbox" id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn6CheckBox" name="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn6CheckBox"><span id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indext6" class="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Index_0">Other GP Clinics</span></td>
</tr>
</tbody></table><table cellspacing="0" cellpadding="0" style="border-width:0;">
<tbody><tr>
<td><div style="width:20px;height:1px"></div></td><td><a href="javascript:__doPostBack('ctl00$cphMain$ctlEsnSearchByServices$Treecontrol_Left_0$Tree_Index','t1730b784-94ca-42d3-80aa-1c9c064e271c\\2fb1d7f3-1a31-4846-ab0c-76adbccf008c')"><img style="border-width:0;" alt="Collapse Other Clinics" src="/WebResource.axd?d=PtoZaOE4OJ68kA17eB1Ru-nLDbZ-ilvB8z5abVJ8BfKZp0iKKZ8iPpsV8tJ5bLWmNAAyfP3gCpxQRyrUtuHqeJKGILYd8Nbb3deoYK17HD9ZYyeS0&t=634604712479085897"></a></td><td class="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Index_1"><input type="checkbox" id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn7CheckBox" name="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn7CheckBox"><span id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indext7" class="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Index_0">Other Clinics</span></td>
</tr>
</tbody></table><table cellspacing="0" cellpadding="0" style="border-width:0;">
<tbody><tr>
<td><div style="width:20px;height:1px"></div></td><td><div style="width:20px;height:1px"><img alt="" src="/WebResource.axd?d=J9BSVEmYJ2R79DzKPp_KwudhxkmRYjt31taLGpqjHFuG3gyciimdNIz2hfef3rMTcgKKF9rZcFetwoS-fvXnw3uYWh88CZ98-dNXPYEoMwTaffwZ0&t=634604712479085897"></div></td><td><img alt="" src="/WebResource.axd?d=Ptpr_s5NKQd2NhXQH_MiSClxDVR5ZHar9QZwFenhB3L_8-vIXRA_NHlxqP3iWPQWzSbDizVZ5YO8o3q4fX1XUhismQEMBdpf8AuHvaSyrvYco4WB0&t=634604712479085897"></td><td class="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Index_1"><input type="checkbox" id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn8CheckBox" name="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn8CheckBox"><span id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indext8" class="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Index_0">Community Geriatric Clinics</span></td>
</tr>
</tbody></table><table cellspacing="0" cellpadding="0" style="border-width:0;">
<tbody><tr>
<td><div style="width:20px;height:1px"></div></td><td><div style="width:20px;height:1px"><img alt="" src="/WebResource.axd?d=J9BSVEmYJ2R79DzKPp_KwudhxkmRYjt31taLGpqjHFuG3gyciimdNIz2hfef3rMTcgKKF9rZcFetwoS-fvXnw3uYWh88CZ98-dNXPYEoMwTaffwZ0&t=634604712479085897"></div></td><td><img alt="" src="/WebResource.axd?d=Ptpr_s5NKQd2NhXQH_MiSClxDVR5ZHar9QZwFenhB3L_8-vIXRA_NHlxqP3iWPQWzSbDizVZ5YO8o3q4fX1XUhismQEMBdpf8AuHvaSyrvYco4WB0&t=634604712479085897"></td><td class="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Index_1"><input type="checkbox" id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn9CheckBox" name="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn9CheckBox"><span id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indext9" class="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Index_0">Community VWO Clinics</span></td>
</tr>
</tbody></table><table cellspacing="0" cellpadding="0" style="border-width:0;">
<tbody><tr>
<td><div style="width:20px;height:1px"></div></td><td><div style="width:20px;height:1px"><img alt="" src="/WebResource.axd?d=J9BSVEmYJ2R79DzKPp_KwudhxkmRYjt31taLGpqjHFuG3gyciimdNIz2hfef3rMTcgKKF9rZcFetwoS-fvXnw3uYWh88CZ98-dNXPYEoMwTaffwZ0&t=634604712479085897"></div></td><td><img alt="" src="/WebResource.axd?d=Ptpr_s5NKQd2NhXQH_MiSClxDVR5ZHar9QZwFenhB3L_8-vIXRA_NHlxqP3iWPQWzSbDizVZ5YO8o3q4fX1XUhismQEMBdpf8AuHvaSyrvYco4WB0&t=634604712479085897"></td><td class="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Index_1"><input type="checkbox" id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn10CheckBox" name="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn10CheckBox"><span id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indext10" class="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Index_0">Counselling Service</span></td>
</tr>
</tbody></table><table cellspacing="0" cellpadding="0" style="border-width:0;">
<tbody><tr>
<td><div style="width:20px;height:1px"></div></td><td><div style="width:20px;height:1px"><img alt="" src="/WebResource.axd?d=J9BSVEmYJ2R79DzKPp_KwudhxkmRYjt31taLGpqjHFuG3gyciimdNIz2hfef3rMTcgKKF9rZcFetwoS-fvXnw3uYWh88CZ98-dNXPYEoMwTaffwZ0&t=634604712479085897"></div></td><td><img alt="" src="/WebResource.axd?d=Ptpr_s5NKQd2NhXQH_MiSClxDVR5ZHar9QZwFenhB3L_8-vIXRA_NHlxqP3iWPQWzSbDizVZ5YO8o3q4fX1XUhismQEMBdpf8AuHvaSyrvYco4WB0&t=634604712479085897"></td><td class="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Index_1"><input type="checkbox" id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn11CheckBox" name="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn11CheckBox"><span id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indext11" class="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Index_0">Physiotherapy Service</span></td>
</tr>
</tbody></table><table cellspacing="0" cellpadding="0" style="border-width:0;">
<tbody><tr>
<td><div style="width:20px;height:1px"></div></td><td><div style="width:20px;height:1px"><img alt="" src="/WebResource.axd?d=J9BSVEmYJ2R79DzKPp_KwudhxkmRYjt31taLGpqjHFuG3gyciimdNIz2hfef3rMTcgKKF9rZcFetwoS-fvXnw3uYWh88CZ98-dNXPYEoMwTaffwZ0&t=634604712479085897"></div></td><td><img alt="" src="/WebResource.axd?d=Ptpr_s5NKQd2NhXQH_MiSClxDVR5ZHar9QZwFenhB3L_8-vIXRA_NHlxqP3iWPQWzSbDizVZ5YO8o3q4fX1XUhismQEMBdpf8AuHvaSyrvYco4WB0&t=634604712479085897"></td><td class="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Index_1"><input type="checkbox" id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn12CheckBox" name="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn12CheckBox"><span id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indext12" class="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Index_0">Private Medical Centres</span></td>
</tr>
</tbody></table><table cellspacing="0" cellpadding="0" style="border-width:0;">
<tbody><tr>
<td><div style="width:20px;height:1px"></div></td><td><div style="width:20px;height:1px"><img alt="" src="/WebResource.axd?d=J9BSVEmYJ2R79DzKPp_KwudhxkmRYjt31taLGpqjHFuG3gyciimdNIz2hfef3rMTcgKKF9rZcFetwoS-fvXnw3uYWh88CZ98-dNXPYEoMwTaffwZ0&t=634604712479085897"></div></td><td><img alt="" src="/WebResource.axd?d=BOvsSO2B3BKMupOSRxbma89ER-i_r1FrqfnVsgVq_QiVog3IJUebdD29i4BVAo26-lbJh_BLXmsQGU_VArXhNt6ejiWJk87whzKer6ts-_kM9Vt90&t=634604712479085897"></td><td class="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Index_1"><input type="checkbox" id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn13CheckBox" name="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn13CheckBox"><span id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indext13" class="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Index_0">Psychiatric Outpatient Rehabilitation Centres</span></td>
</tr>
</tbody></table><table cellspacing="0" cellpadding="0" style="border-width:0;">
<tbody><tr>
<td><div style="width:20px;height:1px"></div></td><td><img alt="" src="/WebResource.axd?d=BOvsSO2B3BKMupOSRxbma89ER-i_r1FrqfnVsgVq_QiVog3IJUebdD29i4BVAo26-lbJh_BLXmsQGU_VArXhNt6ejiWJk87whzKer6ts-_kM9Vt90&t=634604712479085897"></td><td class="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Index_1"><input type="checkbox" id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn14CheckBox" name="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indexn14CheckBox"><span id="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Indext14" class="ctl00_cphMain_ctlEsnSearchByServices_Treecontrol_Left_0_Tree_Index_0">Polyclinics</span></td>
</tr>
</tbody></table>
</div>