Javascript 我的RadioButtonList的jQuery代码有什么问题

Javascript 我的RadioButtonList的jQuery代码有什么问题,javascript,jquery,Javascript,Jquery,我有一个UserControl“Day”,它在另一个UserControl中重复了5次,在一周的5个工作日内,这意味着每天都有1个UserControl。在这个UserControl中有RadioButtonList rdlAmountSlot,它用下面的数据重复了4次 rdlAmountSlot_0 - Amount1 --- (1 - 100) rdlAmountSlot_1 - Amount2 --- (100 - 1000) rdlAmountSlot_2 - Amount3 --- (

我有一个UserControl“Day”,它在另一个UserControl中重复了5次,在一周的5个工作日内,这意味着每天都有1个UserControl。在这个UserControl中有RadioButtonList rdlAmountSlot,它用下面的数据重复了4次

rdlAmountSlot_0 - Amount1 --- (1 - 100)
rdlAmountSlot_1 - Amount2 --- (100 - 1000)
rdlAmountSlot_2 - Amount3 --- (1000 - 10000)
rdlAmountSlot_3 - Amount4 --- (10000 - 100000)
我使用下面的代码进行用户确认

$(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,"");
    });
});
$(文档).ready(函数(){
$(“[id^='rdlAmountSlot.'][type='radio']”)。更改(函数(){
var radioBtnId=this.id;
var$this=$(this);
radconfirm('您确定要选择此插槽吗?',函数(arg){
如果(arg==true){
$find(“”)。设置_值(“”);
}    
否则{
$this.sides('input').prop('checked',true);
var rdlAmountSlot=document.getElementById(radioBtnId);
rdlAmountSlot.checked=false;
$this.prop('checked',false);
}
}, 300, 100,"");
});
});
以上代码抛出确认框5次。原因是什么?如何解决?

更新

下面是我每天的标记代码

<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>

以下是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>

这是与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>

插槽0
插槽1
插槽2
插槽3

如果您尝试使用
每一个
它都会工作,那么可能会出现这种情况

$(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,"");
        })
    });
});
$(文档).ready(函数(){
$(“[id^='rdlAmountSlot.'][type='radio']”)。每个(函数(){
$(this).change(function(){
var radioBtnId=this.id;
var$this=$(this);
radconfirm('您确定要选择此插槽吗?',函数(arg){
如果(arg==true){
$find(“”)。设置_值(“”);
}    
否则{
$this.sides('input').prop('checked',true);
var rdlAmountSlot=document.getElementById(radioBtnId);
rdlAmountSlot.checked=false;
$this.prop('checked',false);
}
}, 300, 100,"");
})
});
});

可能
$this.prop('checked',false)调用
change
event这是一个很大的“否”。我已经对整个else代码进行了注释,但仍然重复了5次。如果您有5组4个单选按钮,它们的ID相同,则可能是导致问题的原因。试着留下3组4个单选按钮,看看它是否重复3次。在这种情况下,只需向它们添加不同的类属性,并相应地更改$(“[id^='rdlAmountSlot'][type='radio']”选择器,使其更精确。
$find(“”)。设置值(“”)
可以调用
change
Too您可以发布包含所有5个控件的HTML,以便我们可以在JS fiddle上尝试它吗?每个控件现在重复4次