如何更改jQuery中的标签文本?
问题描述:
我有一个单选按钮列表,单击单选按钮项目时,我必须更改其标签的文本。但由于某种原因,它不起作用。代码如下:
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>
请指教
Please Advise
答
ASP.Net 自动为服务器端控件生成唯一的客户端ID 。
更改为
Change it to
$('#<%= lblVessel.ClientID %>')
在ASP.Net 4.0中,还设置了 ClientIDMode
属性改为静态
。
In ASP.Net 4.0, you could also set the ClientIDMode
property to Static
instead.