我是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
}
我只想知道计时器用完后启用弹出窗口的代码。
最佳答案
您需要做的就是选择模式(使用jQuery)并调用其modal()
方法:
$("#myModal").modal();
这将调用模式。我还修改了您的Fiddle,以便在此处给您一个示例:JSFiddle Example。