form id form a distinguished name

When the form is often previously written form, do not write the id and name, always feel that there is no use. Later, a look at the background of complete sets of pages found that they make up the name, I do not know why, they looked at the statistics, I'm surprised, if at all, as I did not have to write data to the server. Submit the original form data entered by the user, is controlled in accordance with the form control form element name value. Then form controls inside the id is doing? Is to distinguish the different form controls, there is a role, is to click on a form control also allows the prompt information form control receives focus effect, and improve the user experience with the label, when the label properties for a form control with id consistent , I was always confused, thought it was the same with name value of the control, because look at the example always name value with the same id value.

  This leads to another problem is the label usage: is used for indicating which form elements with bindings. There are two ways associated with it, for one display associated with, one is not shown for the implicit association.

     Display is associated with so-called label with form elements are juxtaposed relationship

<label for='sex'>性别:</label>
<input type='text' id='sex' name='gender'>

See here id and name value is not necessarily the same as

Implying that label is associated with a form element that contains the relationship, this time the label there is no need for, form elements do not need id

<label>性别:<input type='text' name='gender'></label>

See here no id can be, but the name is a must, it will be easy to remember ah!

Then we go back to the theme form the difference in the form of id and name, it said before is the difference between some of the html structure, and said the following about their other differences.

If the writing style, he can only get form elements marked with id

If you add interactivity to use js form element, name and id are selected label form elements, but there are different forms, document.getElementById ( "sex"). Value, if the acquisition document.forms with name [0] .gender.value

Guess you like

Origin www.cnblogs.com/rickdiculous/p/11469421.html