我有一个表格:的Javascript - 重定向到网页表单提交后
<form name="orderform" onsubmit="submitForm()">
HTML HERE
.
.
.
<button type="submit" name="submitbutton" id="submitbutton">Submit</button>
和功能:
function submitForm()
{
submitted = true;
goHome(submitted);
}
和
function goHome(submitted)
{
if(redirect == submitted)
{
alert("form submitted");
document.location.href = "index.html";
}
}
我试图让我的网页显示一条警告消息,然后在提交表单后重定向到index.html,但我似乎无法以任何方式得到它。 我试过在提交按钮时使用onClick
,或者纯粹用Javascript提交表单(document["orderform].submit();
和document.getElementById("orderform");
),但没有奏效。
我的猜测是这些函数在提交的同时被执行,导致提交对它们执行。所以,我加setTimeout
为function goHome();
要执行或试用window.onload = goHome();
,但似乎没有任何工作。
有什么建议吗?
PS:我没有使用jQuery。
我不知道这是如何工作,谷歌似乎没有给我任何回报。此外,我在本地主机。 – YoshimitsU