jsfor循环问题!
var a = "1,2,3,4,5,6,7,8,9,10,11,12";
怎么输出:
1 2 3 4 5
6 7 8 9 10
11 12
------解决方案--------------------
你要在js中输出 ?
不知道 ,我只知道 alert出来
var a = "1,2,3,4,5,6,7,8,9,10,11,12";
var arrs = a.split(",") ;
var count = 0;
var str = '' ;
for (var i = 0; i < arrs.length; i++ ){
str = str + arrs[i] + ' ' ;
count++ ;
if (count % 5){
alert(str) ;
str = '' ;
count = 0 ;
}
}
------解决方案--------------------
<html>
<head>
<script language="javascript">
function init(){
var a = "1,2,3,4,5,6,7,8,9,10,11,12";
var arrs = a.split(",") ;
var count = 0;
var str = '' ;
for (var i = 0; i < arrs.length; i++ ){
str = str + arrs[i] + ' ' ;
count++ ;
if (count == 5){
alert(str) ;
str = '' ;
count = 0 ;
}
}
alert(str) ;
}
</script>
</head>
<body onload= "init()">
</body>
</html>