FF和IE兼容的捕获回车事件问题
//注册火狐监听键盘事件
document.onkeydown = keyDown;
//键盘事件处理
function keyDown(e) {
//判断浏览器
if(document.all) {
//IE
alert(event.keyCode);
} else {
var keycode = e.which;
var realkey = String.fromCharCode(e.which);
alert("按键码: " + keycode + " 字符: " + realkey);
}
}
document.onkeydown = keyDown;
//键盘事件处理
function keyDown(e) {
//判断浏览器
if(document.all) {
//IE
alert(event.keyCode);
} else {
var keycode = e.which;
var realkey = String.fromCharCode(e.which);
alert("按键码: " + keycode + " 字符: " + realkey);
}
}
技术改变生活!