2016-02-08 39 views
0

我想確認然後重定向到新頁面。Onclick確認,然後重定向

如果我在confirm之前刪除return它確認任何一種方式,但如果我保留return它不會重定向到鏈接。

<button name="payment" class="btn btn-xs-6 btn-danger btn-block" type="button" 
    onclick="return confirm('are you sure you want to cancel?');window.location.href='cancel';" 
    value="fav_HTML">Cancel Payment 
</button> 
+0

笑,爲什麼這個問題是向下投?我沒有看到任何反對stackoverflow規則。 –

回答

3

您需要的confirm()值,這表明如果用戶確認或取消。所以,相反的

return confirm('are you sure you want to cancel?'); window.location.href='cancel'; 

你應該做的

if (confirm('are you sure you want to cancel?')) window.location.href='cancel'; 
+0

它的工作謝謝你! –

0
r = confirm('are you sure you want to cancel?'); 
if (r == true) { 
    window.location.href='cancel'; 
} else { 
    // 
} 
+1

'confirm()'只返回布爾值,所以'if(r == true)'可以替換爲'if(r)'。 – LostMyGlasses

+0

@LostMyGlasses,當然 – AshBringer