我想在我的ASP.Net页面上显示一条消息,例如点击保存按钮上的“保存记录”。 5秒后,我想隐藏它。
我该怎么做JavaScript?我可以避免添加jQuery(我没有使用它)吗?
答案 0 :(得分:9)
您可以使用setTimeout
函数,该函数允许您将来推迟回调的执行。所以你可以在页面中放置以下内容:
<script type="text/javascript">
window.setTimeout(function() {
// This will execute 5 seconds later
var label = document.getElementById('IdOfTheElementYouWantToHide');
if (label != null) {
label.style.display = 'none';
}
}, 5000);
</script>
由于使用ASP.NET进行ID名称修改,您可以使用class selector。一旦你开始这样做,你的用户开始问你添加一些淡出效果,你会很快意识到像jQuery这样的框架可能会派上用场。
答案 1 :(得分:3)
您可以使用JavaScript通知插件Pines Notify
查看link更多选择
答案 2 :(得分:1)
你可以使用jQuery的jGrowl加载项 - 这为这种场景提供了“Mac风格”的通知。