2011-02-16 36 views
2

我有這個按鈕會將用戶發送到頁面,但首先要求用戶確認,但它不能正常工作,我該如何解決?由於使用window.location並一起返回確認

<input class="cancel" type="button" value="Cancel" onclick="window.location.href='<?php bloginfo('home'); ?>';return confirm('Are you sure you want to delete your post?');" />

回答

2

寫一個新的函數

void redirect(url) { 
    if (confirm('Are you sure you want to delete your post?')) { 
    window.location.href=url; 
    } 
    return false; 
} 

然後從onclick

onclick="redirect('<?php bloginfo('home'); ?>');" 
1

打開命令周圍。您正在離開當前頁面,,然後進行確認。這是行不通的。

if (confirm(...)) window.location.href='....' 
+0

重定向**不**工作時,雖然我點擊確定按鈕? – Cameron 2011-02-16 19:27:54

7

試試這個:

<input class="cancel" type="button" value="Cancel" onclick="if (confirm('Are you sure you want to delete your post?')) window.location.href='http://www.google.com';" />