关于数组的数组再循环, 各位帮忙..
有个数组arrArray[arr1[],array2[], ...] , arr1[],arr2[]也是数组,包含多少也不知道.
需要循环arrArray里arr1,arr2...的值各取一个放到temp里.
例如 假设:advArray[arr1[1,2,3],arr2[4,5]]
能生成如下.
temp[1,4]
temp[2,5]
temp[3,4]
temp[1,5]
...
用setInterval()来循环, 每次一个temp[], 每次得到temp跟上次不一样
(比如:现在结果是temp[1,4],则下一次出来是temp[2,5] 这样循环).
------解决方案-------------------- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN ">
<html>
<head>
<title> arrtest.html </title>
<meta http-equiv= "keywords " content= "keyword1,keyword2,keyword3 ">
<meta http-equiv= "description " content= "this is my page ">
<meta http-equiv= "content-type " content= "text/html; charset=UTF-8 ">
<!-- <link rel= "stylesheet " type= "text/css " href= "./styles.css "> -->
</head>
<script type= "text/javascript ">
//数组值计算
var sid=null; //线程id
var limit=0; //setInterval 次数限制
var timems=100; //setInterval 周期
var k=0; //内部运算参数
function pageinit()
{
var arr=[[1,2,3,7,5,9,0],[4,3,8],[6,4],[2,9,2,4]]; //传入数组
Start(arr);
}
function Start(arr)
{
sid=window.setInterval(function(){doArr(arr)},timems);
}
function Close()
{
if(sid)window.clearInterval(sid);
}
function doArr(arr)
{
limit++;
if(limit> 60)Close(sid); //到60次停止setInterval
var temp=new Array();
for(i=0;i <arr.length;i++)
{
temp.push(getArrValue(arr[i],k));
}
k++;
createLi( 'result ',temp);
}
function getArrValue(arr,i)
{
if(i> =arr.length)
i=i%arr.length;
return arr[i];
}
//结果报表
function createLi(strE,Txt)
{
var e=document.getElementById(strE);
e=e.childNodes[0];
var li=document.createElement( 'li ');
var liTxt=document.createTextNode(Txt);
li.appendChild(liTxt);
e.appendChild(li);
}
</script>
<style type= "text/css ">
#result ul{margin:0 0;color:darkred;font-size:12px;}
#result ul li{list-style:none;}
</style>
<body onload= "pageinit() ">
<div> [[1,2,3,7,5,9,0],[4,3,8],[6,4],[2,9,2,4]] </div>
<div id= "result ">
<ul>
<li> 数组结果 </li>
</ul>
</div>
</body>
</html>