1.for循环
for(......){
.........;
}
实例:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>cycle</title>
<script type="text/javascript">
/*var aList01 = ['a','b','c','d'];
var aLen = aList01.length;
for(var i=0;i<aLen;i++){
alert(aList01[i]);
}*/
window.onload = function(){
var oUl = document.getElementById('ul');
var aList = ['美人鱼','大黄蜂','变形金刚','海王'];
var sTr = '';
for(var i=0;i<aList.length;i++){
sTr += '<li>' + aList[i] + '</li>';
}
/*alert(sTr);*/
oUl.innerHTML = sTr;
}
</script>
<style type="text/css">
.ulcon{
width: 300px;
height: 300px;
list-style: none;
margin: 50px auto 0;
}
.ulcon li{
height: 70px;
line-height: 70px;
border-bottom: 1px dotted #000;
}
</style>
</head>
<body>
<ul class="ulcon" id="ul">
<!--<li>美人鱼</li>
<li>美人鱼</li>
<li>美人鱼</li>
<li>美人鱼</li>-->
</ul>
</body>
</html>
2.while循环
var ....
while(....){
.......
i++;
}
3.数组去重
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>repea</title>
<script type="text/javascript">
var aList01 = [1,2,4,5,5,8,4,7,8,4,6,1,9,5,4,9];
var iLen = aList01.length;
var aList02 = [];
for(var i=0;i<iLen;i++){
if(aList01.indexOf(aList01[i])==i){ /*每个重复数字的位置是第一个*/
aList02.push(aList01[i]);
}
}
alert(aList02);
</script>
</head>
<body>
</body>
</html>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。