需要在 Datalist 中实现 javascript 校验

Need to implement javascript valiadation in Datalist

您好,我的页面布局如下图所示

我想要的是点击尺寸复选框内部单选按钮自动检查,点击石头重置内部单选按钮列表自动检查。

我的 HTML 代码看起来像

<asp:DataList ID="dtbindjewellery" runat="server"  OnItemDataBound="dtbindjewellery_ItemDataBound" Width="100%">
            <ItemTemplate>
                             <div class="col-md-12 col-sm-12 col-xs-12 jewelerymain">
                                <asp:CheckBox ID="Servicechkbox" runat="server" Text='<%#Eval("ServiceName")%>' />
                                <asp:HiddenField ID="hdserviceid" runat="server" Value='<%#Eval("ServiceId")%>' />                                    
                            </div>
                 <%-- Sizing Radiobutton--%>                                 
                        <div id="divsizing" runat="server" class="col-md-12 col-sm-12 col-xs-12 subservices" visible="false">
                            <asp:RadioButton ID="rdsizing1" runat="server" GroupName="ringsize" />                                
                            <asp:DropDownList ID="ddselectSize" runat="server"></asp:DropDownList>
                            <br />
                            <asp:RadioButton ID="rdsizing2" runat="server" GroupName="ringsize" />                                
                            <asp:TextBox ID="txtsize" runat="server" CssClass="txtNumericUpDownExtender"></asp:TextBox>

                        </div>
                       <%-- Stone resetting Radiobutton--%>                                 
                        <asp:RadioButtonList ID="radiosub" runat="server"></asp:RadioButtonList>                   
            </ItemTemplate>
        </asp:DataList>

这里的尺寸调整有 2 个独特的单选按钮,宝石重置有单选按钮列表。

我是根据不同的id绑定的,checkbox和radio的id在数据列表中获取变化

我应该如何对 javascript 中的复选框点击进行验证?

使用如下。

 function Specialinstruction() {
        var datalist = document.getElementById("<%=dtbindjewellery.ClientID%>");
        var count = datalist.rows.length;

        for (i = 0; i < count; i++) {
            var chkid = document.getElementById('ContentPlaceHolder1_JewelleryServices_dtbindjewellery_Servicechkbox_' + i);
            //var checkboxid = document.getElementById(id);
            if (chkid.checked == true) {
                // alert("hello");
                var hdservice = document.getElementById('ContentPlaceHolder1_JewelleryServices_dtbindjewellery_hdserviceid_' + i);
                var value = hdservice.value;

                if (value == 3) {
                    var rdsizing1 = document.getElementById('ContentPlaceHolder1_JewelleryServices_dtbindjewellery_rdsizing1_' + i);
                    var rdsizing2 = document.getElementById('ContentPlaceHolder1_JewelleryServices_dtbindjewellery_rdsizing2_' + i);
                    if (rdsizing1.checked == false && rdsizing2.checked == false)
                    { rdsizing1.checked = true; }
                }
}
}

   <asp:CheckBox ID="Servicechkbox" CssClass="cb" onClick="Specialinstruction();" runat="server" Text='<%#Eval("ServiceName")%>' />