2015-06-19 81 views
1

我是一名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 
} 

我只是想知道的代碼,使彈出的時間用完之後。

+0

在你的例子中你使用引導? 你可以使用bootstrap模態插件: [link] http://www.w3schools.com/bootstrap/bootstrap_modal.asp –

回答

3

所有你需要做的是選擇模式(使用jQuery),並調用其modal()方法:

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

將調用模式。我也修改了你的小提琴在這裏給你一個例子:JSFiddle Example

+0

非常感謝!解決了我的問題! – user61092

相關問題