Javascript 使用window.location和return一起确认

Javascript 使用window.location和return一起确认,javascript,Javascript,我有一个按钮,它将用户发送到一个页面,但首先要求用户确认,但它不能正常工作,我如何修复它?谢谢 将命令转过来。您将离开当前页面,然后执行确认。那不行 if (confirm(...)) window.location.href='....' 试试这个: <input class="cancel" type="button" value="Cancel" onclick="if (confirm('Are you sure you want to delete your post?'))

我有一个按钮,它将用户发送到一个页面,但首先要求用户确认,但它不能正常工作,我如何修复它?谢谢


将命令转过来。您将离开当前页面,然后执行确认。那不行

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';" />

编写一个新函数

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'); ?>');"
onclick=“重定向(“”);”

当我单击“确定”按钮时,重定向不起作用?没有错误,它只是不执行重定向:/我使用了上面的函数。谢谢你的帮助!