In a page, there are many controls (elements or labels). To make it easier to manipulate these labels, you need to identify an identity card for these tags.
The required attributes are: Name, ID, class
1. Name
Specifies the name of the label.
1.1 Format:
<input type= "text" name= "username"/>
1.2 Application Scenarios
①form form: Name can be used as a variable name to be forwarded to the server's list of forms, such as the name of the upload to the server above: Username= ' text value ';
②input type= ' Radio ' radio label: When you set the name of several radio labels to the same value, a single selection operation is performed.
<type= "Radio" name= ' sex '/> male <type= "Radio" name= ' Sex ' /> Women
③ quickly get a set of tags with the same name: Get a label with the same name, and work with it, such as changing attributes, registering events, and so on;
function Changtxtcolor () { var txts = document.getelementsbyname ('txtcolor//For(// 'red';}}
1.3 Features
The value of the Name property is not unique in the current page.
2. Id
Specifies the unique identification of the label.
2.1 Format:
<input type=password id= "userpwd"/>
2.2 Application Scenarios:
① Gets the label object quickly, based on the unique ID number provided. such as: document.getElementById (ID)
② is used to act as the label label for property value: Example: <label for= ' userid ' > Username: </label>, which indicates that the label with ID UserID has the focus when this label is clicked.
2.3 Features
The value of the id attribute, if it is unique on the current page.
3. Class
Specifies the class name of the label.
3.1 Format:
<input Type=button class= "btnsubmit"/>
3.2 Application Scenarios:
①css operation, put some specific styles into a class, you need the label of this style, you can add this class.
3.3 Features:
Multiple classes can be placed in a class attribute, but must be separated by a space, such as:class=' btnsubmit btnopen '
Original address: http://www.cnblogs.com/polk6/archive/2013/05/28/3101571.html
The difference between Class,id and name