使用Javascript 怎样对表格加快捷键,有实例最好

我在java中,要在页面上加快捷键,对表格进行操作,使用 Javascript 怎样对表格加快捷键,有实例最好.
[b]问题补充:[/b]
谢谢你!可不可以在每行中加文本框加快捷键

麻烦楼主以后说问题一次性说清楚,说得太模糊了,浪费答题人的时间,也浪费自己的时间。
刚才照楼主的要求,又写了一个,可能代码有点乱,多多包涵(IE only)。
[code="js"]

function RegKeyMove(id){ var grid=document.getElementById(id); var curRow=0,curCol=0,lastSelectedRow=0,lastSelectedCol=0; var rowCount=grid.childNodes[0].childNodes.length-1; var colCount=grid.childNodes[0].childNodes[0].childNodes.length-1; var KeyMoveConfig={}; KeyMoveConfig.doMove=function(){ var key=event.keyCode; if(key==37){ curCol<=0?curCol=0:curCol--; };//若keyCode为37则按的是左键 else if(key==38){ curRow<=0?curRow=0:curRow--; }//若keyCode为38则按的是向上键 else if(key==39){ curCol>=colCount?curCol=colCount:curCol++; }//若keyCode为38则按的是右键 else if(key==40){ curRow>=rowCount?curRow=rowCount:curRow++; }//若keyCode为40则按的是向下键 if(lastSelectedRow!=curRow){ grid.childNodes[0].childNodes[curRow].style.backgroundColor="red";//改变当前行颜色 grid.childNodes[0].childNodes[lastSelectedRow].style.backgroundColor="white";//重置原始行颜色 } KeyMoveConfig.setEditor(curRow,curCol); } KeyMoveConfig.setEditor=function(row,col){ if(!(lastSelectedRow==curRow && lastSelectedCol==curCol)){ var text=grid.childNodes[0].childNodes[curRow].childNodes[curCol].innerHTML; grid.childNodes[0].childNodes[curRow].childNodes[curCol].innerHTML= "<input type='text' value='"+text+"' style='background-color:#538387' />";//将当前行内容改变为文本框 grid.childNodes[0].childNodes[lastSelectedRow].childNodes[lastSelectedCol].innerHTML= grid.childNodes[0].childNodes[lastSelectedRow].childNodes[lastSelectedCol].childNodes[0].value;//将原始列的内容还原为普通文本。 setTimeout(function(){grid.childNodes[0].childNodes[curRow].childNodes[curCol].childNodes[0].select();},"0");//选中文本框。关于延迟时间为0的setTimeout,楼主可以查看一下相关资料。这是一个很著名的IE Bug。 lastSelectedRow=row; lastSelectedCol=col; } } grid.childNodes[0].childNodes[0].style.backgroundColor="red";//将第一行变为红色。 /*将第一个单元格的内容改为文本框*/ var text=grid.childNodes[0].childNodes[0].childNodes[0].innerHTML; grid.childNodes[0].childNodes[0].childNodes[0].innerHTML= "<input type='text' value='"+text+"' style='background-color:#538387' />"; setTimeout(function(){grid.childNodes[0].childNodes[0].childNodes[0].childNodes[0].select();},"0");//选中文本框 grid.onkeyup=KeyMoveConfig.doMove;//绑定方法doMove到onkeyup事件。 } window.onload=function(){ RegKeyMove('myGrid');//注册事件。 }

somethingsomethingsomething
somethingsomethingsomething
somethingsomethingsomething
somethingsomethingsomething
somethingsomethingsomething


[/code]

刚写了一个,可以正确运行,楼主将就着看吧(IE only):
[code="js"]

function RegKeyMove(id){ var grid=document.getElementById(id); grid.childNodes[0].childNodes[0].style.backgroundColor="red";//改变第一行TR颜色。 var curRow=0,lastSelected=0,rowCount=grid.childNodes[0].childNodes.length-1; var KeyMoveConfig={}; KeyMoveConfig.doMove=function(){ var key=event.keyCode; if(key==38){ curRow<=0?curRow=0:curRow--; }//若keyCode为38则按的是向上键 else if(key==40){ curRow>=rowCount?curRow=rowCount:curRow++; }//若keyCode为40则按的是向下键 if(lastSelected!=curRow){ grid.childNodes[0].childNodes[curRow].style.backgroundColor="red";//改变当前行颜色 grid.childNodes[0].childNodes[lastSelected].style.backgroundColor="white";//重置原始行颜色 lastSelected=curRow; } } grid.onkeyup=KeyMoveConfig.doMove;//绑定方法doMove到onkeyup事件。 } window.onload=function(){ RegKeyMove('myGrid');//注册事件。 }

somethingsomethingsomething
somethingsomethingsomething
somethingsomethingsomething
somethingsomethingsomething
somethingsomethingsomething


[/code]