javascript 在特定时间后隐藏“div”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4731999/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 14:42:41  来源:igfitidea点击:

Hide 'div' after specific amount of time

javascriptjquery

提问by I-M-JM

I have a div, which is generally used for showing some status messsage like "you have selected some xyz thing"

我有一个 div,它通常用于显示一些状态消息,比如“你选择了一些 xyz 的东西”

Now, I need to hide it at interval of specific amount of time (say, 60 secs) after page loads.

现在,我需要在页面加载后以特定的时间间隔(例如 60 秒)隐藏它。

Code:

代码:

 <div id="msg">You have selected 'Time and Money' magazine</div>

How can I perform the above mentioned thing?

我该如何执行上述操作?

Thanks

谢谢

回答by Lance

$(document).ready(function () {
  setTimeout(function () {
      $('#msg').hide();
  }, 60000);
});

回答by naveen

To hide msg after 60 seconds, do this

要在 60 秒后隐藏 msg,请执行以下操作

$("#msg").fadeOut(60000);

回答by coreyward

This should do what you need: jQuery Timers

这应该可以满足您的需求:jQuery Timers

$(function(){
  $(document).oneTime(60000, function(){
    $('#msg').hide();
  });
});

回答by Alpesh

you can use setTimeoutthis -

你可以使用setTimeout这个 -

$('document').ready(function(){
  window.setTimeout('test()',time in milliseconds);
});

function test(){

  $('#divid').hide();

}

回答by nunopolonia

You can use jQuery's 1.4 delay function

你可以使用jQuery的1.4延迟功能