使用计时器使asp标签不可见

时间:2013-04-18 05:38:36

标签: asp.net timer label visible

我必须显示一个标签,表明数据插入成功。标签应该在5秒后自动消失,我该如何实现?

 <html>
 <head id="Head1" runat="server">
 <title>Test Visibility</title>
 <script type="text/javascript">
  $(document).ready(function () {
    setTimeout(function () {
        $('#<%= lblError.ClientID%>').hide();
    }, 100); // <-- time in milliseconds
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:Label ID="lblError" runat="server" Text="Label"></asp:Label>
</div>
 </form>
</body>
</html>

1 个答案:

答案 0 :(得分:2)

您可以使用jquery。
调用一个函数,它会在特定的持续时间后隐藏它。

setTimeout(function() {
   $('#labelId').hide();
}, 1000); // <-- time in milliseconds

假设您有一个标签

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

所以你可以按照以下方式使用它

  setTimeout(function() {
   $('#<%= lblResult.ClientId%>').hide();
}, 1000); // <-- time in milliseconds

并在document.ready中调用它。

$(document).ready(function() {
       setTimeout(function() {
   $('#<%= lblResult.ClientId%>').hide();
}, 1000); // <-- time in milliseconds
});
相关问题