我有这个按钮会将用户发送到页面,但首先要求用户确认,但它不能正常工作,我该如何解决?由于使用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?');" />
我有这个按钮会将用户发送到页面,但首先要求用户确认,但它不能正常工作,我该如何解决?由于使用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?');" />
写一个新的函数
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'); ?>');"
打开命令周围。您正在离开当前页面,,然后进行确认。这是行不通的。
if (confirm(...)) window.location.href='....'
试试这个:
<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';" />
重定向**不**工作时,虽然我点击确定按钮? – Cameron 2011-02-16 19:27:54