3
I가 포커스 이벤트가 나는 다음과 같은 출력을 얻을 IE8에서 아래의 코드에서 처리에 문제 :IE 포커스 이벤트 핸들러는 지연
LOG: set focus txt1
LOG: set focus txt2
LOG: txt1 focus
LOG: txt2 focus
다른 모든 브라우저에서 출력은 다음과 같습니다
LOG: set focus txt1
LOG: txt1 focus
LOG: set focus txt2
LOG: txt2 focus
을 IE8은 모든 포커스 요청을 대기열에 넣고 현재 함수가 끝난 후 이벤트 핸들러를 실행하는 것 같습니다.
IE8이 다른 브라우저처럼 잘 작동하도록하는 해결 방법이 있습니까?
<html>
<head>
</head>
<body>
<script>
function test(){
console.log('set focus txt1');
document.getElementById('txt1').focus();
console.log('set focus txt2');
document.getElementById('txt2').focus();
}
</script>
<input id="txt1" type="text" onfocus="javascript:console.log('txt1 focus')" style="width:100px" />
<input id="txt2" type="text" onfocus="javascript:console.log('txt2 focus')" style="width:100px" />
<button value="Click" onclick="javascript:test()"></button>
</body>
</html>