//第一步把之前的数据写成一个数组的形式,定义变量为 infos
var arr=[ ['小A','女',21,'大一'], ['小B','男',23,'大三'],
['小C','男',24,'大四'], ['小D','女',21,'大一'],
['小E','女',22,'大四'], ['小F','男',21,'大一'],
['小G','女',22,'大二'], ['小H','女',20,'大三'],
['小I','女',20,'大一'], ['小J','男',20,'大三']
]
document.write('将表显示出来'+"<br>");
for(var i=0;i<9;i++)
{
for(var j=0;j<4;j++)
{
document.write(arr[i][j]+" "+" ")
}
document.write("<br>");
}
document.write('<br>');
document.write("进行第一次筛选,条件是都是大一"+"<br>");
for(var i=0;i<9;i++)
{
if(arr[i][3]=='大一')
{
for(var j=0;j<4;j++)
{document.write(arr[i][j]+" "+" ");}
document.write("<br>");
}
}
document.write("<br>");
document.write("第二次进行筛选,条件是全是女生"+"<br>");
for(var i=0;i<9;i++)
{
if((arr[i][3]=='大一')&&(arr[i][1]=='女'))
{
for(var j=0;j<4;j++)
{document.write(arr[i][j]+" "+" ");}
document.write("<br>");
}
}
你写这么复杂,不累吗?
<script type="text/javascript">
var infos=[ ["小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(infos[i][3]=="大一"&&infos[i][1]=="女"){
document.write(infos[i][0]+"<br />");
continue;
}
}
</script>
我这个简洁不?简单不??
...