我有一個表格:的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