浏览 3267 次
锁定老帖子 主题:实习时面试的题目(含答案)
精华帖 (0) :: 良好帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2009-03-07
用JavaScript实现一个连动菜单. 下面是我写出来的,也不知道对不对,面试肯定是过不了了....555555..... <html> <head> <title></title> <script type="text/javascript"> function change(){ var leftShow = new Array(); leftShow[0] = "中国"; leftShow[1] = "美国"; var rightShow = new Array(); rightShow[0] = new Array(); rightShow[0][0] = "北京"; rightShow[0][1] = "上海"; rightShow[0][2] = "重庆"; rightShow[1] = new Array(); rightShow[1][0] = "休斯顿"; rightShow[1][1] = "西雅图"; rightShow[1][2] = "纽约"; var s = document.getElementById("selectLeft").value; var selectRight = document.getElementById("selectRight"); //alert(s); if(s == "0"){ for(var j=0;j<rightShow[0].length;j++){ selectRight.remove(i); } for(var i=0;i<rightShow[0].length;i++){ var detailShow = new Option(rightShow[0][i]); //document.getElementById("selectRight").insertBefore(detailShow,selectRight.options[i]); selectRight.appendChild(detailShow); } } else if(s == "1"){ for(var j=0;j<rightShow[1].length;j++){ selectRight.remove(i); } for(var i=0;i<rightShow[1].length;i++){ var detailShow = new Option(rightShow[1][i]); ///document.getElementById("selectRight").insertBefore(detailShow,); obj = document.getElementById("selectRight").appendChild(detailShow); } } } </script> </head> <body> <select id="selectLeft" onchange="change()"> <option value="0" selected="selected">中国</option> <option value="1">美国</option> </select> <select id="selectRight"> <option>北京</option> <option>上海</option> <option>重庆</option> </select> </body> </html> 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2009-10-12
楼主写的这个貌似有问题!
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title></title> <script language="javascript"> function changeCountry() { var cityList = new Array(); /*以数字为下标的数组*/ /*cityList[0] = ['北京','上海','香港','澳门']; cityList[1] = ['拉斯维加斯','纽约','休斯顿','加利福尼亚'];*/ /*以国家为下标的数组 这样可在国家多的时候分清楚数组*/ cityList['中国'] = ['北京','上海','香港','澳门']; cityList['美国'] = ['拉斯维加斯','纽约','休斯顿','加利福尼亚']; //获得国家选项的索引号 // var cIndex = document.form1.selCountry.selectedIndex-1; //获得国家选项的标识 var cIndex = document.form1.selCountry.value; var newOption1; document.form1.selCity.options.length = 0;//清空城市下拉框原有数据 for(var j in cityList[cIndex]) { newOption1 = new Option(cityList[cIndex][j],cityList[cIndex][j]); document.form1.selCity.options.add(newOption1); } } </script> </head> <body> <form id="form1" name="form1" method="post" action=""> 国家: <select name="selCountry" id="selCountry" onChange="changeCountry()"> <option value="--请选择国家--">--请选择国家--</option> <option value="中国">中国</option> <option value="美国">美国</option> </select> <br /> 城市: <select name="selCity" id="selCity"> <option value="--请选择城市--">--请选择城市--</option> </select> <br /> </form> </body> </html> 我写了一个 看楼主用的上不 一起交流交流 |
|
返回顶楼 | |
发表时间:2009-10-17
谢谢哈,一起交流!
|
|
返回顶楼 | |