日期:2014-05-16 浏览次数:20306 次
document.onkeydown = function(e){ var e = window.event?window.event:e; if(e.keyCode==13 || e.which == 13) { alert('tt'); return false; } }
<div><button type="button" id="a">点一下再按回国</button></div> <div> <button type="button" id="b">点一下再按回国</button></div> <script type="text/javascript"> $(document).ready(function(){ document.onkeydown = function(e){ var e = window.event?window.event:e; if(e.keyCode==13 || e.which == 13) { var id=$("button:focus").attr("id"); alert(id); } } }) </script>
------解决方案--------------------
var target = event.target || event.srcElement; switch(target.id) { case "btn1": case "btn2": }