<Button> tag
Definition and usage
<Button> the tag defines a button.
Inside the button element, you can place content, such as text or images. This is the difference between this element and the button created using the input element.
Compared with <input type = "button">, the <button> Control provides more powerful functions and richer content. All content between the <button> and </button> labels is the content of the button, including any acceptable body content, such as text or multimedia content. For example, you can include an image and related text in a button and use them to create an attractive labeled image in the button.
The only prohibited element is image ing because its mouse-and keyboard-sensitive actions interfere with form buttons.
Always define the type attribute for the button. The default type of Internet Explorer is "button", while that of other browsers (including W3C specifications) is "submit ".
Browser support
All mainstream browsers support <button> labels.
Important:If the button element is used in an HTML form, different browsers submit different values. Internet Explorer submits the text between <button> and <button/>, while other browsers submit the content of the value attribute. Use the input element in the HTML form to create a button.
Notes
When using the <button> tag, it is easy to take it for granted as <input type = "button">. This can easily produce the following errors:
1. Get the value of <button id = "customBtn" value = "test"> button </button> value through $ ('# customBtn'). val ().
In IE (IE kernel), the value is "button" instead of "test". Instead of "test" in IE, the value is "test ". In the first sentence marked with red above.
This must be separated from <input type = "button">.
Use these two methods $ ('# mbmbtn'). val (), $ ('# customBtn'). attr ('value') to obtain values in different browsers:
Browser/Value |
$ ('# CustomBtn'). val () |
$ ('# CustomBtn'). attr ('value ') |
Firefoxbench |
Test |
Test |
Chrome15.0 |
Test |
Test |
Opera11.61 |
Test |
Test |
Safari5.1.4 |
Test |
Test |
IE9.0 |
Button |
Button |
Verify this by testing the following code:
2. accidentally put the <button> label in the <form> label, and you will find that clicking this button becomes a submission, which is equivalent to <input type = "submit"/>
For more information, see the second sentence above.
Do not treat the <button> label as an input element in <form>.
Verify this by testing the following code: