From the thin HTML5 spec :
A button element without a specified type attribute is the same as a button element with a type attribute set to "submit".
And the <button type="submit"> submits the form, rather than behaving like a simple <button type="button"> button .
The HTML4 specification says the same thing:
type = submit | button | reset [CI]
This attribute declares the type of button. Possible values:
submit : creates a submit button. This is the default value.reset : create a reset button.button : create a button.
So your <button> elements:
<button class="btn">Button_1</button> <button class="btn">Button_2</button>
same (in compatible browsers):
<button type="submit" class="btn">Button_1</button> <button type="submit" class="btn">Button_2</button>
and every time you click one of these buttons, you submit your form.
The solution is to use simple buttons:
<button type="button" class="btn">Button_1</button> <button type="button" class="btn">Button_2</button>
Some versions of IE use type="button" by default, despite what the standard says. You should always specify the type attribute when using <button> to ensure you get the expected behavior.
mu is too short Mar 10 '12 at 4:12 2012-03-10 04:12
source share