如何使用 Web 控件的 Jquery 将文本分配给标签

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2497588/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 13:37:52  来源:igfitidea点击:

How to assign the text to the label using Jquery for the web controls

asp.netjquery

提问by Vara Prasad.M

i am having and by using jquery ineed to assign another text "hello" to the label "lbl" through the jquery. and if we access the label "lbl" the text "hello" should come because the value "hai" is replaced with "hello" and if we write the below line i should get the new modified lable in aspx.cs file

我正在使用 jquery ineed 通过 jquery 将另一个文本“hello”分配给标签“lbl”。如果我们访问标签“lbl”,文本“hello”应该出现,因为值“hai”被替换为“hello”,如果我们写下一行,我应该在 aspx.cs 文件中得到新的修改标签

my aspx.cs file code is

我的 aspx.cs 文件代码是

switch(lbl.Text)
{
case "hello":
code...
break;
}

回答by rahul

$("#lbl").text('hello');

See .text()

.text()

If the label is inside a naming container, then you can use

如果标签位于命名容器内,则可以使用

$("#<%= lbl.ClientID %>").text("hello");

回答by tribus

$("span[id*='lbl']").text("hello");

回答by Shamjith Haridasan

<script src="jquery-1.7.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function() {
     $("#lbl").text('Hello');
    });
</script>