2015-10-14 73 views
0

我想單擊更新/提交按鈕時更改頁面。這裏是我的提交按鈕代碼:onclick在提交按鈕中有href

<td width="8%"><input type="submit" name="submit" value="Update" onclick="??????????"></td> 

我在需要鏈接/ href的地方放置一個問號。或者你可以建議其他方法來做到這一點,當我點擊更新按鈕,它指示我到另一個PHP文件。謝謝!

回答

2

onclick需要。 onclick用於執行JS。這通過爲<form>設置action屬性來完成。

<form method="POST" action="anotherPHPFile.php"> 
    <input type="submit" name="submit" value="Update"> 
</form> 

點擊按鈕後,您將被重定向到anotherPHPFile.php

+0

這是正確的,但不是在我的編碼。因爲我在這行代碼下面有一個更新數據庫查詢,所以當我把你的建議停止代碼閱讀直到那裏,並切換到另一個PHP文件。當我點擊「提交」按鈕然後切換到另一個php文件時,如何首先更新數據庫。謝謝! – mercury

+0

然後將操作更改爲相同的PHP文件。提交後,使用'header(「Location:anotherPHPFile.php」);'查詢並重定向 –

0

這樣做!

function redirect(e){ 
 
//If you want to check something here can prevent defualt button action 
 
    // e.preventDefault() 
 

 
//now do your action. 
 

 
// similar behavior as an HTTP redirect 
 
window.location.replace("http://stackoverflow.com"); 
 

 

 
// you can also use this line to do similar behavior as clicking on a link 
 
// window.location.href = "http://stackoverflow.com"; 
 

 

 
}
<input type="submit" name="submit" value="Update" onclick="redirect()">