js让某个动作延迟几秒执行
setTimeout(function (){
$(button).linkbutton('enable');
}, 3000);
js延迟函数delay的使用
const delay = ms => new Promise((resolve, reject) => setTimeout(resolve, ms))
const getData = status => new Promise((resolve, reject) => {
status ? resolve('done') : reject('fail')
})
const getRes = async (data) => {
try {
const res = await getData(data)
const timestamp = new Date().getTime()
await delay(1000)
console.log(res, new Date().getTime() - timestamp)
} catch (error) {
console.log(error)
}
}
getRes(true) // 隔了1秒
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。