如何更改标签的文字?
我有一个单选按钮列表,单击单选按钮项目时,我必须更改其标签的文本。但由于某种原因它不起作用。代码如下:
<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>
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:
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
我遇到了同样的问题,因为我正在使用
我了解到您可以使用临时 jquery 方法先清除它,然后追加:
或者按照惯例,您可以使用:
OR
I was having the same problem because i was using
I learned that you can either use the provisional jquery method to clear it first then append:
Or conventionaly, you could use:
OR
ASP.Net 自动为服务器端控件生成唯一的客户端 ID。
将其更改为
在 ASP.Net 4.0 中,您还可以设置 将
ClientIDMode
属性改为Static
。ASP.Net automatically generates unique client IDs for server-side controls.
Change it to
In ASP.Net 4.0, you could also set the
ClientIDMode
property toStatic
instead.试试这个:
id$=
将匹配以该文本结尾的元素,这就是 ASP.NET 自动生成 ID 的方式。您可以使用span[id=$=lblVessel]
使其更安全,但通常这是没有必要的。Try this:
The
id$=
will match the elements that end with that text, which is how ASP.NET auto-generates IDs. You can make it safer usingspan[id=$=lblVessel]
but usually this isn't necessary.试试这个
$("label").html(your value);
或$("label").text(your value);
try this
$("label").html(your value);
or$("label").text(your value);
我自己刚刚经历过这个并找到了解决方案。请参阅 ASP.NET 标签服务器控件实际上被重新渲染为跨度(而不是输入),因此使用 .val() 属性来获取/设置将不起作用。相反,您必须在跨度上使用“text”属性并结合使用控件的 .ClientID 属性。以下代码将起作用:
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:
我们必须基于此找到属性值的标签标记。我们已经替换了标签文本。
脚本:
Html
您想要了解更多详细信息。请单击此处
we have to find label tag for attribute value based on that.we have replace label text.
Script:
Html
You want to more details .Click Here
ASP.net Label 将在浏览器中呈现为跨度。所以用户'html'。
ASP.net Label will be rendered as a span in the browser. so user 'html'.
在 JS 中尝试一下:
单击标签文本可将其切换为替代文本,同时选择关联的输入字段并将焦点移至同一关联的输入字段。
Try this in JS:
Clicking on the label text toggles it with an alternative text, while selecting the associated input field and giving the focus to the same associated input field.