<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript">
var secs = 5;
function Load(){
for(var i=secs;i>=0;i--)
{
//if(parseInt(i)==0){
//i=5;
//}else{
window.setTimeout('doUpdate('+i+')', (secs-i) * 1000);
// }
}
}
function doUpdate(num){
document.getElementById('showDiv').innerHTML = '<h2>'+num+'...</h3>';
}
</script></head>
<body>
<script>
window.setTimeout("Load()",1000);
</script>
<div id="showDiv"></div>
</body>
</html>
我想知道为什么把注释的部分加上代码就有问题了,我是想在页面不断的显示5 4 3 2 1 0 5 4 3 2 1 0 5 4 3.....有大侠
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript">
var secs = 5;
function Load(){
for(var i=secs;i>=0;i--)
{
//if(parseInt(i)==0){
//i=5;
//}else{
window.setTimeout('doUpdate('+i+')', (secs-i) * 1000);
// }
}
}
function doUpdate(num){
document.getElementById('showDiv').innerHTML = '<h2>'+num+'...</h3>';
}
</script></head>
<body>
<script>
window.setTimeout("Load()",1000);
</script>
<div id="showDiv"></div>
</body>
</html>
我想知道为什么把注释的部分加上代码就有问题了,我是想在页面不断的显示5 4 3 2 1 0 5 4 3 2 1 0 5 4 3.....有大侠
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript">
var i=5;
function Load(){
doUpdate(5);
}
function doUpdate(num){
document.getElementById('showDiv').innerHTML = '<h2>'+num+'...</h3>';
window.setTimeout(function(){doUpdate(i)},(5-i)*1000);
i=i-1;
if(i==0){
i=5;
}
}
</script></head>
<body>
<script>
window.setTimeout("Load()",1000);
</script>
<div id="showDiv"></div>
</body>
</html>
这样试试
var secs = 5;
function Load(){
for(var i=secs;i>=-1;i--)
{
//if(parseInt(i)==0){
//i=5;
//}else{
window.setTimeout('doUpdate('+i+')', (secs-i) * 1000);
// }
}
}
function doUpdate(num){
document.getElementById('showDiv').innerHTML = '<h2>'+num+'...</h3>';
if(num<0){ Load(); }
}
</script>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<div id="showDiv"></div>
<script>
var secs = 5;
function Load(){
if(secs == 0){
secs = 5;
}else{
secs--;
}
doUpdate(secs);
setTimeout(arguments.callee, 1000);
} function doUpdate(num){
document.getElementById('showDiv').innerHTML = '<h2>'+num+'...</h3>';
} setTimeout(Load, 1000);
</script>
</body>
</html>