【问题标题】:Change Radio Button selected item text during post back using jQuery使用 jQuery 在回发期间更改单选按钮选定的项目文本
【发布时间】:2012-04-24 12:42:32
【问题描述】:

我在update panel 中有一个类似此代码的单选按钮列表:

<asp:RadioButtonList ID="RadioButtonList1" runat="server" Width="233px" 
                ClientIDMode="Static" AutoPostBack="true" 
                onselectedindexchanged="RadioButtonList1_SelectedIndexChanged">
                <asp:ListItem Value="1">1</asp:ListItem>
                <asp:ListItem Value="2">2</asp:ListItem>
                <asp:ListItem Value="3">3</asp:ListItem>
                <asp:ListItem Value="4">4</asp:ListItem>
            </asp:RadioButtonList>

当用户单击此单选按钮的任何项目时,我希望显示 Please Wait... 文本而不是单选按钮文本。我编写此代码:

function pageLoad() {
        $(document).ready(function () {
            $('#RadioButtonList1').on("change", function () {
                $("#RadioButtonList1 input:checked").val("Please Wait...");
            });
       });
    }

但它不起作用。我的错误在哪里?

谢谢

【问题讨论】:

  • 记得检查 readiobuttonList 的 Id 是否正确,因为在渲染服务器控件时,ID 会有所不同。

标签: jquery asp.net asp.net-ajax updatepanel


【解决方案1】:

您应该更改此代码:

$("#RadioButtonList1 input:checked").val("Please Wait...");

to

$("#RadioButtonList1 input:checked").parent().find('label').text("Please Wait");

【讨论】:

    【解决方案2】:

    radio 按钮值不会显示在浏览器视口上,您应该使用labels 并更改其文本:

       $(document).ready(function () {
                $('#RadioButtonList1').on("change", function () {
                    $("#RadioButtonList1 input:checked").closest("label").text("Please Wait...");
                });
           });
    

    【讨论】:

      【解决方案3】:

      省略函数调用,只需在您的 javascript 代码块中使用它:

      $(document).ready(function () {
          $('#RadioButtonList1').on("change", function () {
              $("#RadioButtonList1 input:checked").val("Please Wait...");
          });
      

      });

      【讨论】:

        【解决方案4】:

        尝试:

        function pageLoad() {
                $(document).ready(function () {
                    $('#<%=RadioButtonList1.ClientID %>').on("change", function () {
                       $("#<%=RadioButtonList1.ClientID %>").find("input[checked]").val("Please Wait...");
                    });
               });
            }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2018-11-16
          • 2015-05-24
          • 1970-01-01
          • 1970-01-01
          • 2018-10-15
          • 1970-01-01
          • 2021-07-09
          相关资源
          最近更新 更多