求大神帮忙看看,为什么这个代码只输出一个结果

来源:4-10 编程练习

weixin_慕容9179744

2022-02-28 16:05

<!DOCTYPE  HTML>

<html >

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>流程控制语句</title>

<script type="text/javascript">


 //第一步把之前的数据写成一个数组的形式,定义变量为 infos

var infos=[["大一","大三","大四","大一","大四","大一","大二","大三","大一","大三"],["女","男","男","女","女","男","女","女","女","男"],["小A","小B","小C","小D","小E","小F","小G","小H","小I","小J"]]

 //第一次筛选,找出都是大一的信息


for(var i=0;i<infos.length;i++){

    if(infos[0][i]=="大一"){

            if(infos[1][i]=="女"){

                document.write(infos[2][i]+"<br>");

            }

        

}

}



  

</script>

</head>

<body>

</body>

</html>


写回答 关注

1回答

  • 慕娘0441064
    2022-04-15 10:51:37

    因为infos.length=3,你只循环了i=0,1,2三个数,所以只有1个结果

JavaScript进阶篇

本课程从如何插入JS代码开始,带您进入网页动态交互世界

468061 学习 · 21891 问题

查看课程

相似问题