用jquery响应asp:RadioButtonList的变化



我有下面的代码,当页面加载和用户选择一个单选按钮时,将焦点设置在一个文本框上。

我如何改变这一点,以便如果他们选择最后一个无线电选项"邮件"的焦点不设置为txtPayerName,而不是btnSubmit控件?

 $(function () {
                    SetDefaultPaymentType();
                    $("#txtPayerName").focus();

                $("#rdLstPaymentOptions").change(function () {
                    $("#txtPayerName").focus();
                });
            });

<asp:RadioButtonList ID="rdLstPaymentOptions" runat="server" RepeatColumns="3" RepeatDirection="vertical"
                    RepeatLayout="Flow" OnPreRender="rdBtnLst_PreRender" TabIndex="1" 
                    ClientIDMode="Static">
                    <asp:ListItem Text="Credit Card&nbsp;&nbsp;&nbsp;" Value="CreditCard" ></asp:ListItem>
                    <asp:ListItem Text="Electronics Fund Transfer&nbsp;&nbsp;&nbsp;" Value="EFT"></asp:ListItem>
                    <asp:ListItem Text="Check By Mail&nbsp;&nbsp;&nbsp;" Value="Mail"></asp:ListItem>
                </asp:RadioButtonList>

如果在每个单选按钮上分别设置更改事件会怎样?

类似:

$("#rdLstPaymentOptions").each(function (index) {  
   if (index == $("#rdLstPaymentOptions").length - 1) {
      // insert code to set change event for last radio button
   }
   else {
      ($this).change = function () {
         $("#txtPayerName").focus(); 
      }
   }
}); 

给单选按钮和提交按钮一个唯一的CSS类,然后使用:

$('.radioClass').click(function() {
    $('.submitClass').focus()
})

最新更新