HTML中<input type="submit" /> 和 <input type="button" /> 主要從元素定義類型、點擊觸發動作兩個方面來區別。 一、元素定義類型的區別: 1、<input type="button" /> 定義為一個可點擊的按鈕。 2、<input type="submit" /> 定義為一個提交按鈕。提交按鈕會把表單數據發送到服務器。 二、點擊觸發動作的區別: 1、<input type="button" /> 如果沒有添加onclick事件的監聽,點擊時沒有任何反應。 2、<input type="submit" /> 默認情況下,點擊后會執行提交form表單的動作。 代碼示例為: <input type="button" onclick="alert('button')" value="button" /> <form name="testform" action="#" onsubmit="alert('Hello')"> <input type="text" name="username" /> <input type="submit" value="Submit" /> </form>
擴展資料: 1、<input type="submit">添加提交的快捷鍵: 給input標簽設置accesskey全局屬性, 讓用戶使用按鍵或組合按鍵來觸發按鈕。 代碼示例為: <form> <div> <label for="example">Let's submit some text</label> <input id="example" type="text" name="text"> </div> <div> <input type="submit" value="Send" accesskey="s"> </div> </form>
2、禁用<input type="submit">的提交:
可以通過簡單地設置input的全局屬性disabled為true來禁用提交動作。
代碼示例為:
<input type="submit" value="Disabled" disabled>
