form表單中的button點擊後會重新載入頁面問題研究
問題
發生在form表單中的button,未綁定任何事件下(form 標籤未指定action、button標籤未綁定event),點擊後卻重新載入頁面
分析
-
官方文件說明
從W3C School button的介紹,type有三種屬性,而不寫type時的預設值則視不同的瀏覽器而定
value description button The button is a clickable button submit The button is a submit button (submits form-data) reset The button is a reset button (resets the form-data to its initial values) -
測試範例
1
2
3
4
5
6
7
8<form action="" method="get">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<button type="" value="Submit">Submit</button>
<button type="reset" value="Reset">Reset</button>
</form>
reference
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
Comment