의 기능 화재 이해가되지 않는 이유 기능 alert()
불이 코드에 indicator
스타일을 설정하기 전에 :자바 스크립트 : 다른 순서
자바 스크립트 :
var MyClass = function()
{
th = this;
th.func = function(){alert('yes');};
th.Click = function(){
document.getElementById('indicator').style.color = "#0f0";
document.getElementById('indicator').innerHTML = "YES";
th.func(); // here it fires before above style changing
};
th.Start = function()
{
var a = document.getElementById('button1');
a.addEventListener('click', th.Click, false);
};
th.Init = function()
{
th.Start();
};
}
var a = new MyClass().Init();
HTML :
<button id='button1'>Click Me</button>
<div id='indicator' style='color:#f00'>NO</div>
다음에 을 발사하고 싶습니다.
. 알림()은 현재 페이지에서 브라우저의 모든 작업을 중지합니다. 따라서 콘텐츠의 다시 그리기도 차단됩니다. 'window.setTimeout (th.func, 0);' – devnull69
@ devnull69와 같은 비 차단 호출을 사용하여 검사 할 수 있으므로 다른 함수 (예 :'alert() 대신'GET()'요청))', 그것은 정상적인 순서대로 행동 할 것인가? –
네, 맞습니다. 비동기 메소드에만 해당됩니다. 모든 동기식의 경우, 나중에 (유휴 모드에서)'setTimeout'을 사용하지 않으면 변경 사항을 볼 수 있습니다. – devnull69