实习时面试的题目(含答案)

刚到了一个公司面试,这是他们面试给出的最后以个题目....

用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" οnchange="change()">
<option value="0" selected="selected">中国</option>
<option value="1">美国</option>
</select>
<select id="selectRight">
<option>北京</option>
<option>上海</option>
<option>重庆</option>
</select>
</body>

</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值