Tutorial on how to use HTML form tags

高洛峰
Release: 2017-02-17 16:07:22
Original
1370 people have browsed it

Forms are the most basic way to interact with user input and server-side data on a Web page. Here we focus on the most basic form content display and take a look at the HTML form form tag usage learning tutorial

In HTML Forms can be used to collect various types of input information from users. A form is actually an area containing form elements. The input information of various elements in this area will eventually be submitted to the program script through the form. For example, common ones include user login, registration, publishing articles, etc., which are all submitted to dynamic programs for processing through forms. This section mainly talks about forms and form elements. How to submit form information to dynamic programs will be discussed in future programming language lessons.
The area of ​​the form uses the

tag to define the scope of the form. The value of the element in
will be submitted to the corresponding address through this form.

Input information
Generally, the tag is used in forms to collect user input information. The input type is determined by type.
The form tag used in most cases is the input tag (). Input types are defined by the type attribute (type). Common input types include text fields, radio buttons, check boxes, drop-down menus, etc.

Text field
The text field can provide users with the function of inputting text. The browser will interpret the text field as a rectangular box. The user moves the cursor to the box and clicks to move the cursor. Move into the frame. Users can type letters, numbers, etc. into the form.
The text field is defined by setting the text value for the type attribute in the tag
<form>  
文本域1:<input type=”text” name=”firstname” />  
文本域2:<input type=”text” name=”lastname” />  
</form>
Copy after login

The browser displays as follows:
Tutorial on how to use HTML form tags

Radio button
Radio button mostly appears in the options for users to enter information when registering. This type of multi-user only allows users to select one result.
The radio button is defined by setting the value of the type attribute to radio

<form>  
<input type=”radio” name=”sex” value=”male” /> 男生   
<input type=”radio” name=”sex” value=”female” /> 女生   
</form>
Copy after login

The display in the browser is:
Tutorial on how to use HTML form tags

Checkbox
Checkbox allows the user to check one or more corresponding options. A common one is to provide users with functions such as remembering their login account when they log in. You can also collect multiple opinions from users on the user survey page.
The check box is defined by setting the value of the type attribute to checkbox in the tag

<form>  
<input type=”checkbox” name=”val1″ />  
前端开拓者不错   
<input type=”checkbox” name=”val2″ />  
前端开拓者一般   
</form>
Copy after login

The browser displays as follows:
Tutorial on how to use HTML form tags

Drop-down menu
The drop-down menu is similar to the radio selection in information selection, but the drop-down menu can accommodate more information. And the dropdown menu can execute additional scripts after selecting the menu value.
The drop-down menu starts with