供大家參考
<!DOCTYPE ?HTML>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>流程控制語(yǔ)句</title>
<script type="text/javascript">
?//第一步把之前的數(shù)據(jù)寫(xiě)成一個(gè)數(shù)組的形式,定義變量為 infos
var infos=new Array();
infos=[
? ? ['小A','女',21,'大一'],
? ? ['小B','男',23,'大三'],
? ? ['小C','男',24,'大四'],
? ? ['小D','女',21,'大一'],
? ? ['小E','女',22,'大四'],
? ? ['小F','男',21,'大一'],
? ? ['小G','女',22,'大二'],
? ? ['小H','女',20,'大三'],
? ? ['小I','女',20,'大一'],
? ? ['小J','男',20,'大三']
? ? ]
?//第一次篩選,找出都是大一的信息
?var j=0;
?var childinfos=new Array();
?for(var i=0;i<infos.length;i++){
? ? ?switch(infos[i][3]){
? ? ? ? ?case "大一":
? ? ? ? ? ? ?childinfos[j]=infos[i];
? ? ? ? ? ? ?document.write(childinfos[j]+'<br/>');
? ? ? ? ? ? ?j++;
? ? ?}
? ? ?}
? document.write(childinfos.length+"<br/>");
? document.write("<br/>");
?//第二次篩選,找出都是女生的信息
?for(var k=0;k<childinfos.length;k++){
? ? ? if(childinfos[k][1]=="女"){
? ? ? ? ? document.write(childinfos[k][0]+'<br/>');
? ? ? }
? }
?
??
</script>
</head>
<body>
</body>
</html>
2016-07-15
<script type="text/javascript">
function Stu(name,sex,age,grade){
?var stu = new Object()
stu.name=name;
stu.sex =sex;
stu.age = age;
stu.grade = grade;
return stu;
}
var stus = [];
stus[0] = Stu("小A","女",21,"大一");
stus[stus.length] = Stu("小B","男",23,"大三");
stus[stus.length] = Stu("小C","男",24,"大四");
stus[stus.length] = Stu("小D","女",21,"大一");
stus[stus.length] = Stu("小E","女",22,"大四");
stus[stus.length] = Stu("小F","男",21,"大一");
stus[stus.length] = Stu("小G","女",22,"大二");
stus[stus.length] = Stu("小H","女",20,"大三");
stus[stus.length] = Stu("小I","女",20,"大一");
stus[stus.length] = Stu("小J","男",20,"大三");
for(var i=0;i<stus.length;i++){
if(stus[i].sex=="女" && stus[i].grade =="大一"){
document.write(stus[i].name+"<br/>");
}
</script>
</head>
<body>
</body>
</html>
2016-07-15
var student=[['小A','女',21,'大一'],['小B','男',23,'大三'],['小C','男',24,'大四'],['小D','女',21,'大一'],['小E','女',22,'大四'],['小F','男',21,'大一'],['小G','女',22,'大二'],['小H','女',20,'大三'],['小I','女',20,'大一'],['小J','男',20,'大三']];
for(var i=0;i<10;i++)
if(student[i][3]=="大一"&&student[i][1]=="女")
{document.write(student[i]+"<br>");}
我這個(gè)比較簡(jiǎn)單,一次求出,沒(méi)依次算大一和女生
2016-07-15