The difference between Class,id and name

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.