<!DOCTYPE HTML> <html > <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <script type="text/javascript"> var infos=[['A','女','21','大一'],['B','男','23','大三'],['C','男','24','大四'],['D','女','21','大一']]; for(var i=0;i<=infos.length;i++) {switch(infos[i][3]) {case 'dayi': if (infos[i][1]=='nv') document.write(infos[i][0]); break; default: document.write("请继续查找!"); break;} } </script> </head> <body> </body> </html>
for(var i=0 in infos){
var c = infos[i][3];
var d = infos[i][0];
switch(c)
{
case "大一":
if(infos[i][1]=='女'){
document.write(d);
}
break;
default:
document.write("请继续查找!");
break;
}
}
楼主你是要这样的效果吗?
<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<infos.length; i++){
if(infos[i][3] == "大一" && infos[i][1] == "女"){
document.write(infos[i][0] + "<br />")
}
}
仅供参考!!!!
switch()不能直接比较两个字符串。
你改成用多个if()吧。如果一定要用switch,就增加一个函数用来判断字符串编号,然后switch()这个编号
比如:
int getNum(char* s)
{
if(!strcmp(s,"a")) return 1;
if(!strcmp(s,"b")) return 2;
return -1;
}
……
int main()
{
……
char s[100];
switch(getNum(s))
{
case 1:
case2:
……
}
}
case和default后面的冒号有问题,你的是在中文输入法下的,还有那个‘nv’也有问题
'dayi'这个拼音是什么鬼???