单击确认然后重定向

时间:2016-02-08 17:07:34

标签: javascript html html5 onclick

我正在尝试确认然后重定向到新页面。

如果我在return之前删除confirm,则会以任何方式确认,但如果我保留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>

2 个答案:

答案 0 :(得分:5)

您需要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';

答案 1 :(得分:0)

r = confirm('are you sure you want to cancel?');
if (r == true) {
    window.location.href='cancel';
} else {
   //
}
相关问题