计时器用完后如何打开模态弹出窗口?

How to open a modal pop up after timer runs out?

我是 JavaScript 的初学者,正在为 Web 应用程序编写 js 代码,但在某一点上卡住了。

我有一个带有 5 秒计时器的网页,在计时器用完后我希望弹出一个模式。

代码我写好了here:

var count=-1; // initially -1 as we are having a delay of 1000ms

var counter=setInterval(timer, 1000); //1000 will  run it every 1 second

function timer()
{
    count=count+1;
    if (count >=6) //+1 than the req time as we have a delay of 1000ms
    {
        clearInterval(counter);
        /////////////what code should go here for the modal to pop up??///////////////////////
        return;
    }
    document.getElementById("timer").innerHTML=count + " secs"; // watch for spelling
}

我只是想知道在计时器用完后启用弹出窗口的代码。

您需要做的就是 select 模态(使用 jQuery)并调用它的 modal() 方法:

$("#myModal").modal();

这将调用模态。我还修改了您的 Fiddle 以在此处为您提供示例:JSFiddle Example.