<form id="form2" name="form2" method="post" action=""> <div>你的身份是: <select name="select1" onchange="onChangeSelect1(this.value)" class="select"> <option value="0">请选择</option> <option value="1">小学生</option> <option value="2">中学生</option> <option value="3">大学生</option> </select>       你最喜欢的科目: <select name="select2"> </select> </div> <input type="button" value="确 定" onclick="alertAndCheck(select1.value,select2.value)"/></form><script type="text/javascript"> var student = new Array(); for(i=0;i<4;i++){ student[i] = new Array(); } student[0][0]=new Option("请选择","请选择"); student[1][0]=new Option("小学物理","小学物理");//new option(text,value); student[1][1]=new Option("小学数学","小学数学"); student[1][2]=new Option("小学语文","小学语文"); student[2][0]=new Option("中学物理","中学物理"); student[2][1]=new Option("中学数学","中学数学"); student[2][2]=new Option("中学语文","中学语文"); student[3][0]=new Option("大学物理","大学物理"); student[3][1]=new Option("大学数学","大学数学"); function alertAndCheck(str1,str2) { if(str1 > 0){ switch (str1){ case '1':str1 = "小学生";break; case '2':str1 = "中学生";break; case '3':str1 = "大学生";break; default:str1 = "出错";break; } alert("你的身份是:"+str1+"\n你最喜欢的科目:"+str2); } else{ alert("请选择身份!") } } function onChangeSelect1( str1_value) { //document.write(str1_value); var select = document.form2.select2; //document.write(student[str1_value].length); if(str1_value > 0){ for( i=0 ;i< student[str1_value].length;i++){ //document.write(student[str1_value][i].innerHTML+student[str1_value][i].value); select.options[i] = new Option(student[str1_value][i].innerHTML,student[str1_value][i].value); //document.write(select.options[i].value) } select.options[0].select = true; } else{ alert("请选择身份!"); } }</script>
添加回答
举报
0/150
提交
取消