在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ 按按鈕後延遲一秒再 location.href ?

按按鈕後延遲一秒再 location.href ?

當(dāng) click後
我是否能延遲一秒後再 location.href ?
在 location.href 之前我會先執(zhí)行 html()

$("button").click(function(){
 $("#x").html('xx');
// 這之間間隔一秒
 location.href='...';
});
回答
編輯回答
半心人

- - ? 是不是誤解了你的意思,你想達(dá)到什么效果?
只是要延遲的話用setTimeout延遲一下不就好了嗎?

// 同步
clickHandler = function () {
    // do something
    setTimeout(function () {
        // do something
    }, 1000)
}
// 異步
clickHandler = function () {
    // do something
    $.post(xxx, function () {
        setTimeout(function () {
            // do something
        }, 1000)
    })
}
2017年11月7日 17:34
編輯回答
扯機(jī)薄

用 Promise 吧

$("button").click(function(){
 $("#x").html('xx')
 let p = new Promise(function (resolve, reject) {
   setTimeout(function () {
     resolve()
   }, 1000)
 })
 p.then(function () {
   location.href='...'
 })
})
2017年11月18日 09:43