简体   繁体   English

我的 RadioButtonList jQuery 代码有什么问题

[英]Whats wrong with my jQuery Code for RadioButtonList

I have a UserControl "Day" that is repeated 5 times in another UserControl for 5 weekdays in a week that means each day 1 UserControl.我有一个 UserControl“Day”,它在另一个 UserControl 中重复 5 次,持续 5 个工作日,这意味着每天 1 个 UserControl。 And in this UserControl has RadioButtonList rdlAmountSlot is repeated 4 times with the below data并且在这个 UserControl 中有 RadioButtonList rdlAmountSlot 使用以下数据重复 4 次

rdlAmountSlot_0 - Amount1 --- (1 - 100)
rdlAmountSlot_1 - Amount2 --- (100 - 1000)
rdlAmountSlot_2 - Amount3 --- (1000 - 10000)
rdlAmountSlot_3 - Amount4 --- (10000 - 100000)

I used the below code for confirmation from the user我使用以下代码进行用户确认

$(document).ready(function(){
    $("[id^='rdlAmountSlot_'][type='radio']").change(function () {
        var radioBtnId = this.id;
        var $this = $(this);
        radconfirm('Are you sure you want to select this slot?', function(arg){
            if (arg == true) {
                $find('<%= FindControl("txtAmount").ClientID %>').set_value("");
            }    
            else {
                $this.siblings('input').prop('checked',true);
                var rdlAmountSlot = document.getElementById(radioBtnId);
                rdlAmountSlot.checked = false;
                $this.prop('checked', false);
            }
        }, 300, 100,"");
    });
});

The above code is throwing confirmation box for 5 times.上面的代码是抛出确认框5次。 What could be the reason and how to resolve it?可能是什么原因以及如何解决?

UPDATE更新

Below is my markup code for each day以下是我每天的标记代码

<asp:UpdatePanel runat="server" ID="pnlUpdate" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="pnlDayView" runat="server">
            <asp:RadioButtonList ID="rdlAmountSlot" CssClass="radio1" runat="server" ClientIDMode="Static">
            </asp:RadioButtonList>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>

Below is the markup for 5 days以下是5天的加价

<table>
    <tr>
        <td>
    <asp:Panel ID="pnlMonday" runat="server" >
        <uc1:My ID="MyMonday" runat="server" />
    </asp:Panel>
        </td>
        <td>

    <asp:Panel ID="pnlTuesday" runat="server" >
        <uc1:My ID="MyTuesday" runat="server" />
    </asp:Panel>

        </td>
        <td>

    <asp:Panel ID="pnlWednesday" runat="server" >
        <uc1:My ID="MyWednesday" runat="server" />
    </asp:Panel>

        </td>
        <td>

    <asp:Panel ID="pnlThursday" runat="server" >
        <uc1:My ID="MyThursday" runat="server" />
    </asp:Panel>

        </td>
        <td>

    <asp:Panel ID="pnlFriday" runat="server" >
        <uc1:My ID="MyFriday" runat="server" />
    </asp:Panel>

        </td>
    </tr>
    <table>

This is the code similar to rdlAmountSlot这是类似于 rdlAmountSlot 的代码

<table id="ctl00_ContentPlaceHolder1_MyAvailability_MyAvailabilityMonday_rdlAvailability" class="radio1" border="0" style="color: #004B59; font-size: 11px; font-family: Arial, Sans-serif; text-align: justify">
                            <tr>
                                <td><span disabled="disabled"><input id="ctl00_ContentPlaceHolder1_MyAvailability_MyAvailabilityMonday_rdlAvailability_0" type="radio" name="ctl00$ContentPlaceHolder1$MyAvailability$MyAvailabilityMonday$rdlAvailability" value="AVL01" disabled="disabled" /><label for="ctl00_ContentPlaceHolder1_MyAvailability_MyAvailabilityMonday_rdlAvailability_0">Slot 0</label></span></td>
                            </tr><tr>
                                <td><input id="ctl00_ContentPlaceHolder1_MyAvailability_MyAvailabilityMonday_rdlAvailability_1" type="radio" name="ctl00$ContentPlaceHolder1$MyAvailability$MyAvailabilityMonday$rdlAvailability" value="AVL02" /><label for="ctl00_ContentPlaceHolder1_MyAvailability_MyAvailabilityMonday_rdlAvailability_1">Slot 1</label></td>
                            </tr><tr>
                                <td><input id="ctl00_ContentPlaceHolder1_MyAvailability_MyAvailabilityMonday_rdlAvailability_2" type="radio" name="ctl00$ContentPlaceHolder1$MyAvailability$MyAvailabilityMonday$rdlAvailability" value="AVL03" /><label for="ctl00_ContentPlaceHolder1_MyAvailability_MyAvailabilityMonday_rdlAvailability_2">Slot 2</label></td>
                            </tr><tr>
                                <td><input id="ctl00_ContentPlaceHolder1_MyAvailability_MyAvailabilityMonday_rdlAvailability_3" type="radio" name="ctl00$ContentPlaceHolder1$MyAvailability$MyAvailabilityMonday$rdlAvailability" value="AVL04" checked="checked" /><label for="ctl00_ContentPlaceHolder1_MyAvailability_MyAvailabilityMonday_rdlAvailability_3">Slot 3</label></td>
                            </tr>
                        </table>

May be if you try with each it would work.可能是如果你尝试each它都会起作用。

$(document).ready(function(){
    $("[id^='rdlAmountSlot_'][type='radio']").each(function () {
        $(this).change(function(){
            var radioBtnId = this.id;
            var $this = $(this);
            radconfirm('Are you sure you want to select this slot?', function(arg){
                if (arg == true) {
                    $find('<%= FindControl("txtAmount").ClientID %>').set_value("");
                }    
                else {
                    $this.siblings('input').prop('checked',true);
                    var rdlAmountSlot = document.getElementById(radioBtnId);
                    rdlAmountSlot.checked = false;
                    $this.prop('checked', false);
                }
            }, 300, 100,"");
        })
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM