本帖最后由 greatyl1 于 2013-07-25 20:27:06 编辑

解决方案 »

  1.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title><script type="text/javascript">
    var now="";
    var text="";
    var tds=[];
    function createDom(tagName,value,num){
    var dom=document.createElement(tagName);
    if(!value){
    }else if(typeof(value)=='string'||typeof(value)=='number'){
    dom.innerHTML=value;
    }else if(value.tagName){
    dom.appendChild(value);
    }
    if(tagName=='td'){
    dom.setAttribute('num',num);
    tds.push(dom);
    dom.onclick=function(){
    clearTdStyle()
    this.style.backgroundColor='red';
    text.value=value;
    now=this;
    }
    }
    return dom;
    }
    function clearTdStyle(){
    for(var i=0;i<tds.length;i++){
    tds[i].style.backgroundColor='white';
    }
    }
    function setTdStyle(dom){
    clearTdStyle();
    text.value=dom.innerHTML;
    dom.style.backgroundColor='red';
    now=dom;
    window.setTimeout(function(){dom.focus()},200);
    }
    function init(){
    var table=document.getElementById("tb");
    var tbody=createDom('tbody');
    text=document.getElementById("show");
    for(var i=0;i<=50;i++){
    tbody.appendChild(createDom('tr',createDom('td','这是第'+i+"行",i)));
    }
    table.appendChild(tbody);
    }
    window.onload=init;
    document.onkeydown=function(e){
    var a=e||window.event;
    var key=a.keyCode;
    var num=parseInt(now.getAttribute('num'));
    if(key==38){
    if(num>0){
    setTdStyle(tds[num-1]);
    }
    }else if(key==40){
    if(num<tds.length-1){
    setTdStyle(tds[num+1]);
    }
    }

    }
    </script>
    </head>
    <body> 
    <input type="text" id="show" value="do"> 
    <table id="tb">  
    </table> 
    <body>
    </body>
    </html>
    不很明白你的意思
      

  2.   

    就是在浏览器右侧如果没有出现滚动条的时候,键盘上下键可以控制TABLE表内的内容。但是有滚动条的时候,键盘上下键就默认成了滚动条上下移动了。
      

  3.   

    处理完键盘事件后,返回false。并取消事件冒泡event.cancelBubble。试试
      

  4.   

    window.document.onkeydown=function(){
     if (event.keyCode == 38) return false;
    }只能向下滚 IE7测试通过