How to change the text of a label?

后端 未结 9 790
刺人心
刺人心 2020-12-12 11:31

I have a radiobutton list and on click on the radio button item I have to change the text of its label. But for some reason it\'s not working. Code is below:



        
相关标签:
9条回答
  • 2020-12-12 11:38

    try this

    $("label").html(your value); or $("label").text(your value);

    0 讨论(0)
  • 2020-12-12 11:40
    $('#<%= lblVessel.ClientID %>').html('New Text');
    

    ASP.net Label will be rendered as a span in the browser. so user 'html'.

    0 讨论(0)
  • 2020-12-12 11:42
    <asp:RadioButtonList ID="rbtnType" runat="server">
        <asp:ListItem Value="C">Co</asp:ListItem>
        <asp:ListItem Value="I">In</asp:ListItem>
        <asp:ListItem Value="O">Out</asp:ListItem>
    </asp:RadioButtonList>
    <br />
    <asp:Label ID="lblLabelName" runat="server"></asp:Label>
    <script type="text/javascript">
        $(document).ready(function() {
            $("#<%=rbtnType.ClientID%>").change(function() {
                var rbvalue = $("input[@name=<%=rbtnType.ClientID%>]:radio:checked").val();
                if (rbvalue == "C") {
                    $('#<%=lblLabelName.ClientID %>').html('text1');
                } else if (rbvalue == "I") {
                    $('#<%=lblLabelName.ClientID %>').html('else text2');
                } else if (rbvalue == "O") {
                    $('#<%=lblLabelName.ClientID %>').html('or elsethistext');
                }
            });
        });
    </script>
    
    0 讨论(0)
  • 2020-12-12 11:49

    I just went through this myself and found the solution. See an ASP.NET label server control actually gets redered as a span (not an input), so using the .val() property to get/set will not work. Instead you must use the 'text' property on the span in conjuntion with using the controls .ClientID property. The following code will work:

    $("#<%=lblVessel.ClientID %>").text('NewText');
    
    0 讨论(0)
  • 2020-12-12 11:49
       lable value $('#lablel_id').html(value);
    
    0 讨论(0)
  • 2020-12-12 11:53

    we have to find label tag for attribute value based on that.we have replace label text.

    Script:

    <script type="text/javascript">
    $(document).ready(function() 
    { 
    $("label[for*='test']").html("others");
    });
    
    </script>
    

    Html

    <label for="test_992918d5-a2f4-4962-b644-bd7294cbf2e6_FillInButton">others</label>
    

    You want to more details .Click Here

    0 讨论(0)
提交回复
热议问题