如何 运行 两个函数之间有延迟

how to run two functions with a delay between them

所以我有一个点击事件,我打算在点击时更改图片标签的“src”,等待几秒钟然后再改回去......

我尝试过的:


function(){ //getting the img
                //changing the src attribute
                
                stTimeout(someCallbackFunction()
                     { //changing src attribut once again}
                           ,3000 //waiting 3 seconds)
}

//and ofcourse eventlistener

但是第二个函数似乎根本没有被使用,我不知道是什么问题!!

它应该看起来像这样:

function funcA(){ /* code */ }

function funcB(){ 
    /* code */

    setTimeout(funcA, 3000); 
}
            

如果你想有两个独立的功能,你可以像@Lynx 242 那样做。如果您想立即指定回调,请这样做:

functionB(){ 
    /* code */

    setTimeout(() => {
        /* code */
    }, 3000); 
}