About the value and name of Html

These two attributes did not clarify the details, so I specifically found information and summarized them.

details of value

The value attribute can actually be considered as a variable that can be assigned a value.
There is a confusing place for value, that is, value is the content of html tags.
I'm going straight to the conclusion: sometimes yes, sometimes no.
I'm going straight to the conclusion: sometimes yes, sometimes no.
I'm going straight to the conclusion: sometimes yes, sometimes no.
For example, the button below, the value of value and btn, the btn in the middle has nothing to do with each other.

<button value="btn">btn<button/>

However, I always have the illusion that the two are related. Because it was confused with another thing. It is the button of the input label.
At this time, the value of value corresponds to the text displayed on the button.
The button label only appeared later, it didn't exist before, and the button could only be realized with input before.

<input type="button" value="btn"> 

Therefore, the value in the input may be directly related to the content of the control. But it's also possible that it doesn't matter.
Such as radio. The two characters of male and female here will not be displayed at all. If you want to display it, you can write it behind the input.

<input type="radio" value="男"> 
<input type="radio" value="女"> 

In short, value is sometimes directly related to the content of html, and sometimes has nothing to do with it, just as a value.
In short, value is sometimes directly related to the content of html, and sometimes has nothing to do with it, just as a value.
In short, value is sometimes directly related to the content of html, and sometimes has nothing to do with it, just as a value.

name details

First of all, there is a method called getElementsByName in the dom to specifically find elements. So name can be used as a lookup identifier. Furthermore, there are special uses in some controls, such as radio, if you set multiple radios with the same name, the radio can achieve the effect of single selection, otherwise the default is still single selection.
Therefore, in general, name has a function similar to group, which is the function of grouping.

Guess you like

Origin blog.csdn.net/ScottePerk/article/details/126819517