Programing

라벨의 텍스트를 변경하는 방법은 무엇입니까?

lottogame 2020. 6. 10. 23:11
반응형

라벨의 텍스트를 변경하는 방법은 무엇입니까?


라디오 버튼 목록이 있고 라디오 버튼 항목을 클릭하면 레이블의 텍스트를 변경해야합니다. 그러나 어떤 이유로 든 작동하지 않습니다. 코드는 다음과 같습니다.

<asp:Label ID="lblVessel" Text="Vessel:" runat="server"></asp:Label>

<script language="javascript">
  $(document).ready(function() {

    $('#rblDiv input').click(function() {
      var selected = $("#rblDiv input:radio:checked").val();
      if (selected == "exportpack") {
        $('#lblVessel').text("NewText");
      }
    });
  });
</script>

ASP.Net 은 서버 측 컨트롤을위한 고유 한 클라이언트 ID를 자동으로 생성합니다 .

로 변경

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

ASP.Net 4.0에서는 ClientIDMode속성Static대신 설정할 수도 있습니다 .


내가 사용하고 있었기 때문에 같은 문제가 발생했습니다.

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

임시 jquery 메소드를 사용하여 먼저 지우고 추가 할 수 있다는 것을 배웠습니다.

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

또는 전통적으로 다음을 사용할 수 있습니다.

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

또는

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

이 시도:

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

id$=ASP.NET이 ID를 자동으로 생성하는 방법입니다 텍스트와이를 요소와 일치합니다. 더 안전하게 사용할 수 span[id=$=lblVessel]있지만 일반적으로 필요하지 않습니다.


이 시도

$("label").html(your value); 또는 $("label").text(your value);


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

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');

$('#<%= lblVessel.ClientID %>').html('New Text');

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


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


   lable value $('#lablel_id').html(value);

참고URL : https://stackoverflow.com/questions/3584145/how-to-change-the-text-of-a-label

반응형