How to change the text of a label?

后端 未结 9 791
刺人心
刺人心 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:54

    I was having the same problem because i was using

    $("#LabelID").val("some value");
    

    I learned that you can either use the provisional jquery method to clear it first then append:

    $("#LabelID").empty();
    $("#LabelID").append("some Text");
    

    Or conventionaly, you could use:

    $("#LabelID").text("some value");
    

    OR

    $("#LabelID").html("some value");
    
    0 讨论(0)
  • 2020-12-12 11:57

    ASP.Net automatically generates unique client IDs for server-side controls.

    Change it to

     $('#<%= lblVessel.ClientID %>')
    

    In ASP.Net 4.0, you could also set the ClientIDMode property to Static instead.

    0 讨论(0)
  • 2020-12-12 11:57

    Try this:

    $('[id$=lblVessel]').text("NewText");
    

    The id$= will match the elements that end with that text, which is how ASP.NET auto-generates IDs. You can make it safer using span[id=$=lblVessel] but usually this isn't necessary.

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