[英]How to prevent form submit from triggering `button:first.onclick()`?
[英]prevent button submit form onclick
我在html按鈕標簽上有問題
這是我的HTML代碼
<form name="data_kirim" action="confirm_order.php" method="POST">
..... order input field ....
<button class="back_button" onclick="window.location.href='keranjang.php'">Back</button>
<input class="next_button" type="submit" name="submit_data_kirim" value="Next"/>
</form>
如何阻止按鈕提交此表單,因為按鈕正在使用href來返回頁面,
有人能幫我嗎?
更改
type='submit'
至
type='button'
<button class="back_button" onclick="window.location.href='keranjang.php'">Back</button>
<form name="data_kirim" action="confirm_order.php" method="POST">
<input class="next_button" type="submit" name="submit_data_kirim" value="Next"/>
</form>
一個快速的解決方案是將后退按鈕移到窗體之外,因為它還沒有使用窗體輸入。
您可以在單擊按鈕時調用javascript中的函數,重定向到您的鏈接並return false
或使用jquery使用preventDefault()
函數
<form onsubmit="return false;">
如果你想讓它鏈接到另一個頁面而不提交表單,那么只需將其設為正常按鈕就像這樣:
<a href="URL">Next</a>
但這不會提交表格。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.