简体   繁体   中英

call two function one after another in javascript settimeout

I need to run following code

document.getElementById("someID").focus();

after below code

setTimeout(function(){loadEditor(param);}, 50);

But i am unable to make it asynchronous.Since I can not modify

function loadEditor(param){ /* some stuff */  }

Is there anyway out to do this? What I have tried till now

setTimeout(function(){
    loadEditor(param);
    document.getElementById("someID").focus();
}, 50);

and

setTimeout(function(){
    $.when( loadEditor('question_stem-text') ).done(function() {
        document.getElementById("someID").focus();
        });
}, 50);

Not successful

//ES6++
const delay = new Promise( (resolve, reject) => {
    setTimeout( () = > {
        loadEditor(param);
        resolve();
    }, 50);
});

delay.then( () => {
    document.getElementById("someID").focus();
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM