我有一个按钮,单击该按钮时会执行两个操作的 myFunction,我希望它执行第一个操作,等待 2 秒,然后执行该操作。这是到目前为止的代码:
function myFunction() {
document.getElementById('box1').style.display = "block"; $("#box2").data( "mmenu" ).close();
};
谢谢!
最佳答案
使用setTimeout
用于提供延迟
function myFunction() {
document.getElementById('box1').style.display = "block";
setTimeout(function() {
// code to execute after delay
$("#box2").data("mmenu").close();
}, 2000);
// -^- delay in milliseconds
};
关于javascript - 在同一功能的操作之间添加时间延迟?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38291628/