簡體   English   中英

等待事件偵聽器加載

[英]Wait for event listener load

我有這部分代碼,在加載時執行了一些操作。

window.addEventListener("load", () => {
        //Something other
    }, false)

當我執行這個 function

this.searchUnit= function (product, supplier, invoice, status) {
            window.location.href = "units.html";
            this.clean();
            title = document.getElementById("viewTitle");
            title.textContent = "Unità";
            sessionStorage.removeItem("product");
            sessionStorage.removeItem("supplier");
            sessionStorage.removeItem("invoice");
            sessionStorage.removeItem("status");

            //Something other...
        }

我需要事件偵聽器 function 的所有操作在執行“this.clean()”之前結束

我怎樣才能做到這一點?

如果您的代碼中的所有其他事情都是同步的,那么可能會將您想要做的所有事情都放在 setTimeout 中的事件偵聽器之后。

setTimeout(functionToBeCalledAfterEventListener,0);

這將確保在執行隊列中的所有內容后執行 function。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM