button & input

很久以前似乎有為這問題困擾過,於是打算作個筆記記錄一下。

button

Button 特別的地方在於它是完整的標籤: <button> 我是 button 的內容 </button> ,這是跟 input 最大的不同點。
標籤內可包入文字、圖片,and more… 除了影像地圖以外其他幾乎都可行,活用性 > input。

使用 button 要注意的地方是要記得先定義type,因 IE 中 type 預設值是 button,其他瀏覽器、W3C則預設為 submit 。
如果沒有事先定義會造成資料傳送錯誤。
而不同瀏覽器中的表單 (form) 中的 button 也會傳送不同值:在 IE 傳送 <button> </button> 之間內容,其他瀏覽器傳送 value 值,所以在 form 要使用 input 。

input

Input type=”button”, Input type=”submit” 顯示的文字是 vaule 值中所包含的文字,未定義的話,預設是 text 。

參考:
[HTML] button type=”button” 和 input type=”button” 的差別
[原] button 和 input type=”button” 的区别
CSS按钮样式之button标签与input type=button的区别详解

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *