Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What's the difference between button and input type=button?

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Most people do not understand the knowledge points of this article "what is the difference between button and input type=button", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "what is the difference between button and input type=button" article.

Label

Definition and usage

The label defines a button.

Inside the button element, you can place content, such as text or images. This is the difference between this element and buttons created using the input element.

Control provides more powerful features and richer content than. Everything between and the tag is the content of the button, including any acceptable body content, such as text or multimedia content. For example, we can include an image and related text in the button and use them to create an attractive tag image in the button.

The only prohibited element is image mapping because its mouse-and keyboard-sensitive actions interfere with the behavior of the form buttons.

Always specify the type property for the button. The default type of InternetExplorer is "button", while the default value in other browsers (including the W3C specification) is "submit".

Browser support

All major browsers support tags.

Important: if you use the button element in an HTML form, different browsers submit different values. InternetExplorer will submit the text between and, while other browsers will submit the contents of the value attribute. Use the input element in the HTML form to create the button.

Matters needing attention

When using tags, it is easy to take them for granted, which can easily lead to the following misuses:

1. Get the value of the button value through $('# customBtn') .val ()

The value used in IE (IE kernel) is "button", not "test", and "test" in non-IE. Participate in the first sentence marked red above.

This should be distinguished from.

The values of $('# customBtn') .val (), $('# customBtn') .attr ('value') in different browsers are obtained in these two ways, as follows:

Browser/Value

('# customBtn'). Val ()

$('# customBtn'). Attr ('value')

Firefox13.0

Test

Test

Chrome15.0

Test

Test

Opera11.61

Test

Test

Safari5.1.4

Test

Test

IE9.0

Button

Button

To verify this, you can test the following code

Copy the code

The code is as follows:

$(function () {)

$('# test1') .click (function () {

Alert ($('# customBtn'). Attr ('value'))

});

$('# test2') .click (function () {

Alert ($('# customBtn') .val ())

});

});

Button

2. If you inadvertently put the tag in the tag, you will find that clicking on the button becomes a submission, which is equivalent to

At this point, you can see the meaning of the second sentence marked red above.

Don't think of tags as input elements in.

To verify this, you can test the following code

Copy the code

The code is as follows:

Button

The above is about the content of this article on "what is the difference between button and input type=button". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report