方式一:
<HTML>
<HEAD><script type="text/javascript">
var mytimer = null; var bar = 0;
function processbar() {
if (bar < 200) {
bar++;
document.getElementById("processbar").style.width = bar + "px";
mytimer = window.setTimeout("processbar()", 50);
}
}
function startbar() {
mytimer = window.setTimeout("processbar()", 50);
}
function pausebar() {
window.clearTimeout(mytimer);
}
</script>
</HEAD>
<BODY>
<div style="width: 200px; height: 10px; border: solid 1px #ccc; padding: 1px;">
<div id="processbar" style="background-color: #90EE90; width: 0px; height: 10px;"></div>
</div>
<input type="button" value="开始" οnclick="startbar();" />
<input type="button" value="暂停" οnclick="pausebar();" />
</BODY>
</HTML>
方式二:
<HTML>
<HEAD>
<script type="text/javascript">
var mytimer = null; var bar = 0;
function processbar() {
if (bar < 200) {
bar++; document.getElementById("processbar").style.width = bar + "px";
}
}
function startbar() {
mytimer = window.setInterval("processbar()", 50);
}
function pausebar() {
window.clearInterval(mytimer);
}
</script>
</HEAD>
<BODY>
<div style="width: 200px; height: 10px; border: solid 1px #ccc; padding: 1px;">
<div id="processbar" style="background-color: #90EE90; width: 0px; height: 10px;"></div>
</div>
<input type="button" value="开始" οnclick="startbar();" />
<input type="button" value="暂停" οnclick="pausebar();" />
</BODY>
</HTML>