我有一个bootstrap加载栏,每250ms更新一次setinterval,所以看起来它正在取得进展。我正在尝试在加载栏达到100%时显示警报和重定向。
<div class="progress" style="border-radius:0px;">
<div class="progress-bar progress-bar-success progress-bar-striped active"
style="border-radius:0px;" id="loading" role="progressbar" aria-valuenow="75"
aria-valuemin="0" aria-valuemax="100" style="width: 0%">
</div>
</div>
我尝试在函数结束前添加window.location
,但它不起作用。我怎样才能做到这一点?也许用if语句?
var percentl = 10;
setInterval(function () {
percentl = percentl + 2;
document.getElementById("loading").style.width = percentl + "%";
}, 250);
答案 0 :(得分:2)
答案 1 :(得分:1)
您可以使用clearInterval
停止计时器,添加if
语句以检查%是否已达到100,location.href
用于重定向网址。
var percentl = 10;
var timer = setInterval(function () {
percentl = percentl + 2;
document.getElementById("loading").style.width = percentl + "%";
if(percentl > 99){
clearInterval(timer);
// do your stuff
location.href = "redirectToThisURL";
}
}, 250);