0

我正在使用下面的脚本来显示复选框的选定 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&amp;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&amp;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&amp;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&amp;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&amp;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 &amp; 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&amp;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>
4

1 回答 1

0

复选框中没有值,您应该将 value 属性添加到输入中,另一方面,输入标签没有关闭

<input type="checkbox" value="Other Services" id="ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Indexn0CheckBox" name="ctl00_cphMain_ctlEsnSearchByServices_ctl05_Tree_Indexn0CheckBox" />
于 2013-05-23T18:31:43.333 回答