且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

5秒后删除新的div

更新时间:2023-12-03 21:26:58

您可以像这样使用setTimeout:

setTimeout(function(){
  $('#divID').remove();
}, 5000);

5000(毫秒)表示5秒.您应该用自己的div/element ID替换divID.

The 5000 (ms) means 5 seconds. You should replace divID with your own div/element id.

您可以使用length确保div首先存在:

You can make sure that the div exists first using length:

setTimeout(function(){
  if ($('#divID').length > 0) {
    $('#divID').remove();
  }
}, 5000)