当前位置: 首页 > 工具软件 > onfire.js > 使用案例 >

js onkeyup 兼容火狐和IE

楮杰
2023-12-01
// 方法1
function keyUp(e) {
	if(navigator.appName == "Microsoft Internet Explorer"){
		var keycode = event.keyCode;
		var realkey = String.fromCharCode(event.keyCode);
	} else {
		var keycode = e.which;
	var realkey = String.fromCharCode(e.which);
	}
	alert("keyCode: " + keycode + " word: " + realkey);
}
// 方法2
function keyUp1(e) {
	var currKey=0,e=e||event;
	currKey=e.keyCode||e.which||e.charCode;
	var keyName = String.fromCharCode(currKey);
	alert("keyCode: " + currKey + " word: " + keyName);
}

//document.onkeyup = keyUp;
document.onkeyup = keyUp1;

 类似资料: