出于某种原因,我将js代码包装在一个立即调用的函数表达式中,我得到了progressBar not defined.想知道为什么会这样吗?
(function(){
"use strict"
var progressBar = function(){
var bar = document.getElementById('pbar'),
status = document.getElementById('status'),
barValue = bar.value;
status.innerHTML = barValue + "%";
bar.value++;
var increment = setTimeout("progressBar()", 50);
if(bar.value == 100){
status.innerHTML = '100% - Straight Besting';
bar.value = '100';
clearTimeout(increment);
}
}
progressBar();
})()
Run Code Online (Sandbox Code Playgroud)