日期:2014-05-16  浏览次数:20461 次

延时显示的问题
页面打开以后,过1分钟,显示“AAAA”,再过1分钟显示“BBBB”,再过一分钟显示“CCCC”,该怎样写?

------解决方案--------------------
<script>
var times = 0;
var str = new Array;;

str[0] = "AAA ";
str[1] = "BBB ";
str[2] = "CCC ";
function _call(){
/*if (times > str.length - 1){
return;
}*/
if (times > str.length - 1){
times = 0;
}
document.getElementById( 'main ').innerHTML = str[times];
times++;
setTimeout( "_call() ",1000)
}
</script>
<body onload= "_call(); ">
<div id= "main "> </div>
</body>

注释掉的是不循环的,现在的是循环显示的~``一分钟等XX毫秒……
------解决方案--------------------
这里 times > str.length - 1
改成
times == str.length
汗~``
------解决方案--------------------
楼上的逻辑不太严谨,俺也发一个,LZ 自选

L@_@K


<body>
<div id= "divOutput "> </div>
<script type= "text/javascript ">
<!--
var arrNews = Array();
arrNews[0] = "早上好! "
arrNews[1] = "中午好! "
arrNews[2] = "晚上好! "
arrNews[3] = "午夜好! "
arrNews[4] = "凌晨好! "

var oOutput = document.getElementById( "divOutput ");
var numNewIndex = 0;
oOutput.innerHTML = arrNews[numNewIndex];

// 时间间隔,单位:毫秒,1s = 1000ms
// 1m = 60s = 60000ms
var numInterval = 1000;
// 是否循环。
var booIsCycle = true;

var numTimerId = window.setInterval(showMessage, numInterval);

function showMessage()
{
numNewIndex++;
oOutput.innerHTML = arrNews[numNewIndex];
if (numNewIndex == arrNews.length-1)
{
if (booIsCycle)
{
numNewIndex = -1;
}
else
{
window.clearInterval(numTimerId);
}
}
}
//-->
</script>
</body>
------解决方案--------------------
上面的不错,你试试
------解决方案--------------------
ttyp(@http://www.cnblogs.com/ttyp/) cool