[html]點選button後畫面被重新整理原因:未設定type="button"
阿新 • • 發佈:2018-11-07
一、問題原因解析:
在form表單裡的button, type 屬性未設定的情況下,Internet Explorer 的預設型別是 "button",而其他瀏覽器中(包括 W3C 規範)的預設值是 "submit:
<form action="form_action.asp" method="get"> First name: <input type="text" name="fname" /> Last name: <input type="text" name="lname" /> <button value="click">click</button> </form>
在非IE下以上程式碼相當於:
<form action="form_action.asp" method="get"> First name: <input type="text" name="fname" /> Last name: <input type="text" name="lname" /> <button type="submit" value="Submit">Submit</button> </form>
此時點選該按鈕就會導致畫面的重新整理。
二、type屬性的值:
值 | 描述 |
---|---|
submit | 該按鈕是提交按鈕(除了 Internet Explorer,該值是其他瀏覽器的預設值)。 |
button | 該按鈕是可點選的按鈕(Internet Explorer 的預設值)。 |
reset | 該按鈕是重置按鈕(清除表單資料)。 |