Home  >  Article  >  Web Front-end  >  A brief discussion on name, value in input and for in label

A brief discussion on name, value in input and for in label

青灯夜游
青灯夜游forward
2018-10-10 17:35:473095browse

This article will briefly talk about name, value in input and for in label. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Input has many attributes, the more commonly used ones are type, value, name, placeholder, multiple, checked, etc. I have always been confused about the name, value, label and the text outside the label, but I finally figured it out today.

1) name attribute

 Definition: The name attribute specifies the name of the input element.

 Usage: The name attribute is used to identify the form data after it is submitted to the server, or to reference the form data through JavaScript on the client.

 Note: Only form elements with the name attribute set can pass their values ​​when submitting the form.

In other words, name is of no use for page display (adding it or not does not affect page display), but is used for easy reference when interacting with the server or writing js.

2) value attribute

Definition: The value attribute sets the value for the input element.

Usage: For different input types, the usage of the value attribute is also different:

  • type="button", "reset", " submit" - Define the text displayed on the button

<input>按钮文字

A brief discussion on name, value in input and for in label

  • type="text", "password", "hidden" - Defines the initial value of the input field

<input>标签外

                                    A brief discussion on name, value in input and for in label

    ##type= "checkbox", "radio", "image" - Defines the value associated with the input What is displayed on the page is the "button text" (text outside the label), and the value at this time is mainly used for interactive operations in js, so the value at this time is generally set to a value related to the input. For example:
  • <input>按钮文字

    Note: The value attribute must be set in and .

3) labelA brief discussion on name, value in input and for in label

The above is the detailed content of A brief discussion on name, value in input and for in label. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete