Javascript表单提交确认与重定向,如果为真

Javascript form submit confirmation with redirect if true

本文关键字:如果 重定向 表单提交 确认 Javascript      更新时间:2023-09-26

这个javascript在提交之前确认表单,但是我不知道如何添加重定向链接,如果它们确认为真,或者如果它们确认为假:

Javascript

<script>
function cancelalert(){
return confirm("By clicking OK you are submitting the form.");
}
</script>

onclick="return cancelalert()"

不直接返回confirm的结果,而是将其放入变量中并相应操作:

var confirmed = confirm("By clicking OK you are submitting the form.");
if(confirmed)
{
  return true; // will sumbit the form. Do a redirect on the server side
}
// not confirmed. Show an alert or something