<style>
.box{
width: 400px;
height: 40px;
border: 1px solid #000000;
}
.box #bon{
background-color: green;
height: 41px;
width: 0px;
text-align: center;
line-height: 40px;
color: #ffffff;
}
</style>
</head>
<body>
<div class="box">
<div id="bon">
<span id="va" style="color:#ffffff ;"></span>
</div>
</div>
</body>
<script>
var val = document.getElementById("bon");
var va = document.getElementById("va");
var num = 0;
var timer = function(){
var x = Math.floor(Math.random()*10);
num +=x;
if(num<=100){
val.style.width=(num + '%');
va.innerHTML=(num + '%')
}else{
val.style.width = ("101%");
va.innerHTML = ("100%");
val.innerText = "下载完毕";
clearInterval(timer);
}
}
setInterval(timer,1000);
</script>