gpt4 book ai didi

javascript - 如何在一分钟后自动关闭 Bootstrap 模式对话框

转载 作者:数据小太阳 更新时间:2023-10-29 05:41:22 24 4
gpt4 key购买 nike

我在我的一个项目中使用 Bootstrap 模式。我正在使用定时器功能来自动显示 Bootstrap 模式。

如果用户在一分钟内没有关闭 Bootstrap 模式。然后它会自动需要关闭 Bootstrap 模式。

如何设置自动关闭bootstrap modal的定时器?

请帮我解决这个问题。

提前致谢:)



var mins;
var secs;
function cd() {
mins = 1 * m("");
secs = 0 + s(":"); // change seconds here (always add an additional second to your total)
console.log(mins);
console.log(secs);
redo();
}
function m(obj) {
for(var i = 0; i ";
if(mins :";
disp += "";
if(secs ";
return(disp);
}
function redo() {
secs--;
if(secs == -1) {
secs = 59;
mins--;
}
$('#myModal').on('shown', function() {
// remove previous timeouts if it's opened more than once.
clearTimeout(myModalTimeout);

// hide it after a minute
myModalTimeout = setTimeout(function() {
$('#myModal').modal('hide');
}, 5000);
});
document.getElementById('timer_container').innerHTML = dis(mins,secs);
if((mins == 1) && (secs == 45)) {
$("#myModal").modal('show');
$('#myModal').on('shown', function() {
// remove previous timeouts if it's opened more than once.
clearTimeout(myModalTimeout);

// hide it after a minute
myModalTimeout = setTimeout(function() {
$('#myModal').modal('hide');
}, 5000);
});
$('.timer-inc').click(function(){
$("#myModal").modal('hide');
href="includes/setSessionTime.php";
$.ajax({
type: "POST",
//data : {cat:"hai"},
cache: false,
url: href,
success: function(data){
console.log(data);
$("#results").html(data);
}
});
});

$('.timer-close').click(function(){
$("#myModal").modal('hide');
href="includes/clearcart.php";
$.ajax({
type: "POST",
//data : {cat:"hai"},
cache: false,
url: href,
success: function(data){
console.log(data);
$("#results").html(data);
}
});
});

$('#myModal').on('hidden', function () {
href="includes/clearcart.php";
$.ajax({
type: "POST",
//data : {cat:"hai"},
cache: false,
url: href,
success: function(data){
console.log(data);
$("#results").html(data);
}
});
});
}
else if((mins == 0) && (secs == 00)){
$("#myModal").modal('hide');
href="includes/clearcart.php";
$.ajax({
type: "POST",
//data : {cat:"hai"},
cache: false,
url: href,
success: function(data){
console.log(data);
$("#results").html(data);
}
});
}
else {
cd = setTimeout("redo()",1000);
}
}
function init() {
cd();
}

最佳答案

尝试

var myModal = $('#myModal').on('shown', function () {
clearTimeout(myModal.data('hideInteval'))
var id = setTimeout(function(){
myModal.modal('hide');
});
myModal.data('hideInteval', id);
})

关于javascript - 如何在一分钟后自动关闭 Bootstrap 模式对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17102116/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com