How do you make an event listener that detects if a boolean variable becomes true?

前端 未结 7 2100
-上瘾入骨i
-上瘾入骨i 2020-12-31 19:52

For example, I have var menu_ready = false;. I have an ajax function that sets menu_ready to true when the ajax stuff is done:

//se         


        
7条回答
  •  不知归路
    2020-12-31 20:34

    One way is continual polling:

    function checkMenu() {
        if (!menu_ready) {
            setTimeout("checkMenu();", 1000);
            return;
        } else {
            // menu_ready is true, so do what you need to do here.
        }
    }
    

    and...

    
    

提交回复
热议问题