function checkEnter(event) {
var charcode;
if (event && event.which) {
charcode = event.which;
alert("Case 1. event.which is " + charcode);
}
else if (event && !event.which) {
charcode = event.keyCode;
alert("Case 2. event.keyCode is " + charcode);
}
document.getElementById("text1").value="";
}
<input type="text" id="text1" onkeyup="checkEnter(event)" />
IE에서 onkeydown이 제대로 작동하지 않는 이유는 무엇입니까?
위의 기능은 IE7와 크롬 모두에서 작동합니다.
<input type="button" id="button1" onclick="checkKeyPressed(event)" value="Button" />
function checkKeyPressed() {
document.onkeydown = function(event) {
var charcode;
if (event && event.which) {
charcode = event.which;
alert("charcode is " + charcode);
}
else if (event && !event.which) {
charcode = event.keyCode;
alert("charcode (keyCode) is " + charcode);
}
}
}
그러나 이것에만 크롬에서 작동합니다. 왜 그런가?
? IE는 약간의 "특별한" –
키를 입력했기 때문에 모든 키에 대해이 이벤트를 발생시키지 않습니다. 하지만 그것은 첫 번째 작품, 그래서 이상한 일종의. – Fabian