如何在javascript中清除标签文本或使标签不可见 [英] How to clear the text of a label or make label invisible in javascript

查看:91
本文介绍了如何在javascript中清除标签文本或使标签不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我的标签定义如下:

< asp:Label ID =lblWarningrunat = serverForeColor =RedVisible =FalseHeight =19pxWidth =276px>



我试图清除标签文字像这样:

hi All,

I have a label defined like this:
<asp:Label ID="lblWarning" runat="server" ForeColor="Red" Visible="False" Height="19px" Width="276px">

I tried to clear the text of a label like this :

function ChangeProperty() {
            var b = document.getElementById('<%=lblWarning.ClientID%>');
if (b!=null)

            {
                b.innerText = "";
}

     }







这不起作用。请帮忙。



谢谢。




This is not working.Please help.

Thanks.

推荐答案

当您将服务器端控件的Visible属性设置为假它甚至没有呈现给客户端,所以你的代码根本找不到它(b将为null)...

如果你想让它在客户端上可见/不可见你必须使用客户端属性...

设置显示或清除显示属性...

When you set the Visible property of a server side control to false it not even rendered to the client, so your code will not found it at all (b will be null)...
If you want to make it visible/invisible on the client you have to play with client side attributes...
Set display or clear the display attribute...
<asp:label id="lblWarning" runat="server" forecolor="Red" height="19px" width="276px" xmlns:asp="#unknown"></asp:label>




function ChangeProperty() {
  var b = document.getElementById('<%=lblWarning.ClientID%>');
  if (b!=null)
  {
    if(b.style.display == "none")
    {
      b.style.display = "";
    }
    else
    {
      b.style.display = "none";
    }
  }
}


这篇关于如何在javascript中清除标签文本或使标签不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆