我正在尝试确认然后重定向到新页面。
如果我在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>
答案 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 {
//
}