因为需要 所以要做一个模拟键盘操作的js 不知可否实现,还请大神们示下,模拟esc退出键操作 当触发js时模拟操作

解决方案 »

  1.   

    KeyboardJS
      

  2.   

    <script type="text/javascript">
    function test(e){
    var a=e||window.event;
    if(a.keyCode==27){
    var div=document.getElementById("test");
    var p=div.parentNode;
    p.removeChild(div);
    }
    }
    document.onkeydown=test;
    </script>
    </head><body>
    <div id="test" style="position:absolute; left:0px; top:0px; width:400px; height:400px; background-color:#FF0000">esc移除</div>
    </body>
    </html>
    类似于这样?