跪求js高手有100分赠送
js高手你好,我写了个菜单,功能是点击键盘的方向键-> 打开它的子菜单,点击键盘的方向键 <-关闭它的子菜单;我想实现 "向键-> "打开子菜单时子菜单能够自动获取焦点(我的菜单是text做的),并且点击ENTER时子菜单能够打开一个URL链接(弹出窗口).
我的代码如下,望高手指点改正:
<html>
<head>
<style type= "text/css ">
<!--
input {border:1px solid #fff; background:#fff; }
input {star : expression(
onmouseover=function(){this.style.backgroundColor= "#eee "},
onmouseout=function(){this.style.backgroundColor= "#fff "})}
.in40 {width:40px;}
.in80 {width:80px;}
.in120 {width:120px;}
.in200 {width:200px;}
-->
</style>
</head>
<body>
<script defer>
var obj=document.getElementsByTagName( "input ");
var urlpath = " ";
for(var i=0;i <obj.length;i++)
if(obj[i].input)
{
obj[i].focus();
break;
}
document.onkeydown=function()
{
try{
//alert(event.keyCode);
if(event.keyCode==13){
//alert( "现在访问URL ");
window.open();
}
//按esc键退出
if(event.keycode == 27)
window.closed();
if(event.keyCode==40){
event.srcElement.nextSibling.nextSibling.focus();
showNone();
}
else if(event.keyCode==38){
event.srcElement.previousSibling.previousSibling.focus();
showNone();
}
else if(event.keyCode==37){
var xxx = event.srcElement;//event.srcElement就是指向触发事件的元素,他是什么就有什么的属性;srcElement 是事件初始目标的html元素对象引用,因为事件通过元素容器层次冒泡,可以在任一层进行处理,所以由一个属性指向产生初始事件的元素是很有帮助的.有了元素的引用,就可以读/写改元素的属性,并调用他的任何方法.
if(xxx.id == "bb "){
bbb.style.display = "none ";
}else if(xxx.id == "cc "){
ccc.style.display = "none ";
}else if(xxx.id == "dd "){
ddd.style.display = "none ";
}
}
else if(event.keyCode==39){
var xxx = event.srcElement;
if(xxx.id == "bb "){
bbb.style.display = "block ";
}else if(xxx.id == "cc "){
ccc.style.display = "block ";
}else if(xxx.id == "dd "){
ddd.style.display = "block ";
}
}
}catch(e){}
}
function url(obj){
urlpath =obj.value;
//window.location.href=obj;
//alert(obj.value);
}
function showNone(){
bbb.style.display = "none ";
ccc.style.display = "none ";
ddd.style.display = "none ";
}
</script>
<table>
<tr> <td>
<div id= "aaa ">
&l