在弹出窗口自动关闭后显示特定时间的弹出窗口

show popup for a particular time after that popup close automatically

本文关键字:窗口 显示 定时间      更新时间:2023-09-26

下面我提到了我的页面内容目前它只显示弹出框一秒钟,但我需要延长时间,我不知道如何做

我使用的脚本

<script type="text/javascript">
window.document.onkeydown = function (e)
{
    if (!e){
        e = event;
    }
    if (e.keyCode == 27){
        lightbox_close();
    }
}
function lightbox_open(){
    window.scrollTo(0,0);
    document.getElementById('light').style.display='block';
    document.getElementById('fade').style.display='block';  
}
function lightbox_close(){
    document.getElementById('light').style.display='none';
    document.getElementById('fade').style.display='none';
}
</script>

我的按钮

<input type="submit"    value="SUBMIT" onclick="lightbox_open();"  />

邮筒

<div id="light">
    <a href="#" onclick="lightbox_close();"></a>
    <h3 th:text="${result}"></h3>
    hi hello
</div>
<div id="fade" onClick="lightbox_close();"></div>

您可以为此使用Window setTimeout()方法。

var t=setTimeout(lightbox_close,3000)

您需要使用window.setTimeout事件。例如,如果您使用的是jQuery:

$(document).ready( function() {
  $('#element').hide();
  window.setTimeout(function() { 
    $('#element').show(); 
  }, 5000);
});

你可以根据自己的需要更换隐藏/展示。

JSFiddle:http://jsfiddle.net/NfCHG/1/