以下のスクリプトを使用して、選択したチェックボックスの ID を表示しています。これは完全に正常に機能しています。値を取得しようとすると、値が返されません。
<div id="selected-ID"></div>
function storeID() {
var ID = $checkboxes.map(function () {
if (this.checked) return this.id; //this.value;
}).get().join(',');
$('#selected-ID').html(ID);
}
$(function () {
$checkboxes = $('input:checkbox').change(storeID);
});
問題は、すべてのチェックボックスがツリービューにあり、ツリーの子ノードにあるチェックボックスのレンダリングされた HTML が次のようになっていることが原因である可能性があります。
これを克服し、ID を変数に格納するにはどうすればよいですか? 光を当ててください。
ツリービュー用にレンダリングされた HTML :
<div style="font-size: 11px; font-family: Tahoma; font-weight: bold; text-align: left;" onclick="OnTreeClick(event)" id="ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Index">
<table cellspacing="0" cellpadding="0" style="border-width:0;">
<tbody><tr>
<td><a href="javascript:__doPostBack('ctl00$cphMain$ctlEsnSearchByServices$ctl05$Tree_Index','tfc052442-3b20-4cdc-8d20-9c8544ac1c6f')"><img style="border-width:0;" alt="Collapse Other Services" src="/WebResource.axd?d=_533LbcrYzxclETTqT9E9lbjpoP9iiSVLn9WP908dD96sH9D2JXH4BN8Q2OdATM4TYJU67kfDSnJQpffp_ITMVu3Y839pir-IzEhB41mqu6U8EWb0&t=634604712479085897"></a></td><td class="toggle ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Index_2"><input type="checkbox" id="ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Indexn0CheckBox" name="ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Indexn0CheckBox"><a style="border-style:none;font-size:1em;" id="ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Indext0" href="javascript:__doPostBack('ctl00$cphMain$ctlEsnSearchByServices$ctl05$Tree_Index','sfc052442-3b20-4cdc-8d20-9c8544ac1c6f')" class="ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Index_0 toggle ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Index_1">Other Services</a></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=Ptpr_s5NKQd2NhXQH_MiSClxDVR5ZHar9QZwFenhB3L_8-vIXRA_NHlxqP3iWPQWzSbDizVZ5YO8o3q4fX1XUhismQEMBdpf8AuHvaSyrvYco4WB0&t=634604712479085897"></td><td class="toggle ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Index_2"><input type="checkbox" id="ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Indexn1CheckBox" name="ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Indexn1CheckBox"><a style="border-style:none;font-size:1em;" id="ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Indext1" href="javascript:__doPostBack('ctl00$cphMain$ctlEsnSearchByServices$ctl05$Tree_Index','sfc052442-3b20-4cdc-8d20-9c8544ac1c6f\\45bb0a98-ec44-e211-beaf-005056ba0039')" class="ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Index_0 toggle ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Index_1">Mobile Services</a></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=Ptpr_s5NKQd2NhXQH_MiSClxDVR5ZHar9QZwFenhB3L_8-vIXRA_NHlxqP3iWPQWzSbDizVZ5YO8o3q4fX1XUhismQEMBdpf8AuHvaSyrvYco4WB0&t=634604712479085897"></td><td class="toggle ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Index_2"><input type="checkbox" id="ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Indexn2CheckBox" name="ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Indexn2CheckBox"><a style="border-style:none;font-size:1em;" id="ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Indext2" href="javascript:__doPostBack('ctl00$cphMain$ctlEsnSearchByServices$ctl05$Tree_Index','sfc052442-3b20-4cdc-8d20-9c8544ac1c6f\\9b3dafdf-217e-e111-9ca9-005056ba0039')" class="ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Index_0 toggle ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Index_1">Hospice Day Care</a></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=Ptpr_s5NKQd2NhXQH_MiSClxDVR5ZHar9QZwFenhB3L_8-vIXRA_NHlxqP3iWPQWzSbDizVZ5YO8o3q4fX1XUhismQEMBdpf8AuHvaSyrvYco4WB0&t=634604712479085897"></td><td class="toggle ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Index_2"><input type="checkbox" id="ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Indexn3CheckBox" name="ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Indexn3CheckBox"><a style="border-style:none;font-size:1em;" id="ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Indext3" href="javascript:__doPostBack('ctl00$cphMain$ctlEsnSearchByServices$ctl05$Tree_Index','sfc052442-3b20-4cdc-8d20-9c8544ac1c6f\\f83dafdf-217e-e111-9ca9-005056ba0039')" class="ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Index_0 toggle ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Index_1">Website - Disability Information Website</a></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=Ptpr_s5NKQd2NhXQH_MiSClxDVR5ZHar9QZwFenhB3L_8-vIXRA_NHlxqP3iWPQWzSbDizVZ5YO8o3q4fX1XUhismQEMBdpf8AuHvaSyrvYco4WB0&t=634604712479085897"></td><td class="toggle ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Index_2"><input type="checkbox" id="ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Indexn4CheckBox" name="ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Indexn4CheckBox"><a style="border-style:none;font-size:1em;" id="ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Indext4" href="javascript:__doPostBack('ctl00$cphMain$ctlEsnSearchByServices$ctl05$Tree_Index','sfc052442-3b20-4cdc-8d20-9c8544ac1c6f\\33333333-217e-e111-9ca9-005056ba0039')" class="ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Index_0 toggle ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Index_1">Information & Referral Services</a></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="toggle ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Index_2"><input type="checkbox" id="ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Indexn5CheckBox" name="ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Indexn5CheckBox"><a style="border-style:none;font-size:1em;" id="ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Indext5" href="javascript:__doPostBack('ctl00$cphMain$ctlEsnSearchByServices$ctl05$Tree_Index','sfc052442-3b20-4cdc-8d20-9c8544ac1c6f\\44444444-217e-e111-9ca9-005056ba0039')" class="ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Index_0 toggle ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Index_1">Ambulance Service (Non-Emergency)</a></td>
</tr>
</tbody></table>
</div>