keydown兼容性

document.onkeydown = keyDown;//IE处理按键事件
//Firefox,若document的属性layers不存在,则window.evnet
if(document.layers){
  document.captureEvents(Event.KEYDOWN);
}
//keyDown()函数原型,IE:冒泡事件,event对象一个keyCode;Firefox:charCode属性
function keyDown(e){
   var ev = (e)?e:(window.event)?window.event:null;
   if(ev){
     return (ev.charCode)?ev.charCode:
	 ((ev.keyCode)?ev.keyCode:((ev.which)?ev.whick:null));
   }
   return -1;
}

你可能感兴趣的:(JavaScript,keydown,javascript兼容性)