dav*_*ara 3 javascript jquery twitter-bootstrap bootbox
我的twitter BootBox打开如下:
bootbox.dialog("{{$steps[0]}}");
Run Code Online (Sandbox Code Playgroud)
十秒后,我关闭我的BootBox,如下所示:
window.setTimeout(function(){
bootbox.hideAll();
}, 10000);
Run Code Online (Sandbox Code Playgroud)
是否有可能在BootBox中显示剩余的秒数直到关闭?
您可以div在邮件中添加,如下所示:
bootbox.dialog("Your message <div id='SecondsRemaining'>10</div>");
Run Code Online (Sandbox Code Playgroud)
然后使用此函数更新它:
(function(){
var remaining = 10; // Number of seconds
var obj = document.getElementById("SecondsRemaining");
var timeout = window.setInterval(function(){
remaining--;
if(remaining==0) {
// Time is up, stop the timer and hide the bootbox
window.clearInterval(timeout);
bootbox.hideAll();
return;
}
obj.innerHTML = remaining; // Update the value displayed
}, 1000); // Decrease counter every second
})();
Run Code Online (Sandbox Code Playgroud)
对于bootbox 4+,格式已更改.应该创建对话框:
bootbox.dialog({ message: "Your message <div id='SecondsRemaining'>10</div>" });
Run Code Online (Sandbox Code Playgroud)