Html difference between the label and the span

From the final point of view, label and span tag display style and function are the same
but the label in existence for the property, but also has a decisive difference

The attributes for the label and form paired

label tags are usually written in the form (form), he is the biggest difference with an ordinary span, is that you can pair and form elements, such as text boxes, radio buttons, check boxes. The pairing method is through the label for the property.

such as

1
2
< INPUT  type = "text"  name = ""  ID = "A" /> < label  for = "B" > Click word text box gets the focus </ label > < br /> 
< INPUT type = "text" name = "" ID = "B" /> < label for = "a" > click word text box gets the focus </ large column   of Html label and span distinction ass = "name">label><br/>

Test code above, you can see when clicking when the word, the label will be based on the value for the property, find the id element corresponding
to say, just click on the text, the corresponding input can get focus

Change the lable span, then added for, but no effect, this is the difference between the span and label.

Functions and quite another for writing

If you do not want to label applied for, but want to back input text and input elements to associate itself, then you can do:

1
<label><input type="checkbox" name="aksd" id="aksd" /> 几个字</label>

The input is to use the label wrap. After keeping the same increase for this effect and input label Effect: Click the text box to select it.

Similarly, the code span the label would not be replaced.

Note: label packet input method is invalid in IE6!

Recommended input and label separation mode, because it is more flexible, you can input the label on each eight-pole could not beat the place, but still related to each other - how loyal and tear-jerking love ah!

Guess you like

Origin www.cnblogs.com/lijianming180/p/12239882.html