Difference between <input type='button'

2018-12-31 07:45发布

There is no such thing as a stupid question, so here we go: What is the difference between <input type='button' /> and <input type='submit' />?

标签: html input types
8条回答
大哥的爱人
2楼-- · 2018-12-31 08:05

A 'button' is just that, a button, to which you can add additional functionality using Javascript. A 'submit' input type has the default functionality of submitting the form it's placed in (though, of course, you can still add additional functionality using Javascript).

查看更多
唯独是你
3楼-- · 2018-12-31 08:06

<input type="button" /> buttons will not submit a form - they don't do anything by default. They're generally used in conjunction with JavaScript as part of an AJAX application.

<input type="submit"> buttons will submit the form they are in when the user clicks on them, unless you specify otherwise with JavaScript.

查看更多
低头抚发
4楼-- · 2018-12-31 08:06

W3C make it clear, on the specification about Button element

Button may be seen as a generic class for all kind of Buttons with no default behavior.

W3C

查看更多
冷夜・残月
5楼-- · 2018-12-31 08:08

<input type="button"> can be used anywhere, not just within form and they do not submit form if they are in one. Much better suited with Javascript.

<input type="submit"> should be used in forms only and they will send a request (either GET or POST) to specified URL. They should not be put in any HTML place.

查看更多
人气声优
6楼-- · 2018-12-31 08:14

IE 8 actually uses the first button it encounters submit or button. Instead of easily indicating which is desired by making it a input type=submit the order on the page is actually significant.

查看更多
高级女魔头
7楼-- · 2018-12-31 08:16

Button won't submit form on its own.It is a simple button which is used to perform some operation by using javascript whereas Submit is a kind of button which by default submit the form whenever user clicks on submit button.

查看更多
登录 后发表回答