表单


名词:

action:每个<form>元素都需要一个action特性,其特性值是服务器上一个页面的URL,这个页面用来在用户提交表单时接收表单中的信息 

method:表单的提交方式可以采取以下两种方式 get和post 

ID:对元素进行唯一标示,用于定位。

<input>:这个元素用来创建多种不同的表单控件,其type特性的值决定了他将要创建那种控件。 

size:size特性不能在新表单中使用,它只在旧的表单中同来指定文本框的宽度(根据可见的字符数量来衡量)  

name:当用户向表单输入信息时,服务器需要知道每条数据被输入到了那个表单控件。每个表单控件都需要一个name特性,这个特性的值对表单控件进行标识并与输入的信息一同传送到服务器。

maxlength:用来限制文本输入区域的字符数量。

type=“password”:建立一个字符被掩盖的文本框。

type=“radio”:单选按钮只让用户在一系列选项中选择其中一个。

type=“file”这个类型的input会创建一个后面附有Browse按钮的类似文本框的控件。点击会打开一个新窗口来让用户在计算机上选择一个文件上传到网站。

type=“submit”提交按钮用来将表单发送到服务器。

type=“image”用图片作为提交按钮

type=“hidden”一个隐藏控件。不会显示出来,但能用浏览器检查功能查看。

type=“date”创建一个日期输入控件

type=“email”如果需要用户提供电子邮件地址,你可以使用电子邮件输入控件。支持HTML5验证机制的浏览器将检查用户提供的信息是不是一个格式正确的电子邮件地址。

type“url”同type=“email”。

type=“email”

type=“search”建立搜索单行文本框

value;value特性为选项指定了被选中时发送到服务器的值。同一组中的每个按钮的值应该各不相同(这样服务器才知道用户选择了哪个选项)

checked:checked特性可用来指定当页面加载时哪个值(如果有的话)会被选中。这个特性的值为checked,同一组中的单选按钮只能有一个使用此特性。

multiple:可以通过添加multiple特性(将该特性的值设置为multiple)来允许用户从这一列表中选择多个选项。

<button>可以让用户更好的控制按钮的显示方式,并允许其他元素出现在<button>元素内。意味着可以在起始标签和结束标签之间结合使用文本和图像。

for:用来声明标签控件标注的是哪个表单控件

<fieldset>可将相关的表单控件置于<fieldset>元素中分成一组。大多数浏览器会显示一条边缘线,只能通过css调整和修改。

<legend>直接跟在起始标签<fieldset>的后面并且包含一个标题,这个标题用来帮助用户理解控件组的用途。

placeholder:在文本框输入文字之前显示的就是placeholder特性的值

<!DOCTYPE html>  
2.<html lang="en">  
3.<head>  
4.    <meta charset="UTF-8">  
5.    <title>表单1</title>  
6.</head>  
7.<body>  
8.<h1>表单结构</h1>  
9.<form action="http://www.example.com/subscribe.php" method="get">  
10.    <p>This is shere the form controls will appear</p>  
11.</form>  
12.<hr>  
13.<h1>单行文本框</h1>  
14.<form action="http://www.example.com/login.php">  
15.    <p>Username  
16.        <input type="text" name="username" size="15" maxlenth"30"/>  
17.    </p>  
18.</form>  
19.<hr>  
20.<h1>密码框</h1>  
21.<form>  
22.    <p>Username:  
23.        <input type="text" name="username" size="15" maxlength="30">  
24.    </p>  
25.    <p>Password:  
26.        <input type="password" name="password" size="15" maxlength="30">  
27.    </p>  
28.</form>  
29.<hr>  
30.<h1>文本域(多行文本框)</h1>  
31.<form action="http://www.example.com/comments.php">  
32.    <p>What did you think of this gig?</p>  
33.    <textarea name="comments" cols="20" rows="4">Enter your comments...</textarea>  
34.</form>  
35.<hr>  
36.<h1>单选按钮</h1>  
37.<form action="http://www.example.com/profile.php">  
38.    <p>Please select your favorite ganre:  
39.        <br/>  
40.        <input type="radio" name="genre" value="rock" checked="checked"/>Rock  
41.        <input type="radio" "radio" name="genre" value="pop"/>POP  
42.        <input type="radio" name="genre" value="jazz"/>Jazz  
43.    </p>  
44.</form>  
45.<hr>  
46.<h1>复选框</h1>  
47.<form action="http://www.example.com/profile.php">  
48.    <p>Plese select your favorite service(s):  
49.        <br/>  
50.        <input type="checkbox" name="service" value checked="checked"/>iTunes  
51.        <input type="checkbox" name="service" value="lastfm"/>Last.fm  
52.        <input type="checkbox" name="service" value="spotify"/>Spotify  
53.    </p>  
54.</form>  
55.<hr>  
56.<h1>下拉列表框</h1>  
57.<form action="http://www.example.com/profile.php">  
58.    <p>What device do you listen to music on?</p>  
59.    <select name="devices">  
60.        <option value="ipod">ipod</option>  
61.        <option value="radio">Radio</option>  
62.        <option value="coputer">Computer</option>  
63.</form>  
64.  
65.</body>  
66.<h1>多选框</h1>  
67.<form action="http://www.example.com/profile.php">  
68.    <p>Do you play any of the following instruments? (You can select more than one option by holding down control on a PC or command key on a Mac while selecting different options.)</p>  
69.    <select name="instruments" size="3" multiple="multiple">  
70.        <option value="guitar" selected="selected">Guitar</option>  
71.        <option value="drums">Drums</option>  
72.        <option value="keyboard" selected="selected">Keyboard</option>  
73.        <option value="bass">Bass</option>  
74.    </select>  
75.</form>  
76.<hr>  
77.<h1>文件上传域</h1>  
78.<form action="http://www.example.com/upload.php" method="post">  
79.    <p>Upload your song in MP3 format:</p>  
80.    <input type="file" name="user-song" /><br />  
81.    <input type="submit" value="Upload" />  
82.</form>  
83.<hr>  
84.<h1></h1>  
85.<h1>提交按钮</h1>  
86.<form action="http://www.example.com/subscribe.php">  
87.    <p>Subscribe to our email list:</p>  
88.    <input type="text" name="email" />  
89.    <input type="submit" name="subscribe" value="Subscribe" />  
90.</form>  
91.<hr>  
92.<h1>图像按钮</h1>  
93.<form action="http://www.example.org/subscribe.php">  
94.    <p>Subscribe to our email list:</p>  
95.    <input type="text" name="email" />  
96.    <input type="image" src="images/subscribe.jpg" width="100" height="20" />  
97.</form>  
98.<hr>  
99.<h1>按钮和隐藏控件</h1>  
100.<form action="http://www.example.com/add.php">  
101.    <button><img src="images/add.gif" alt="add" width="10" height="10" /> Add</button>  
102.    <input type="hidden" name="bookmark" value="lyrics" />  
103.</form>  
104.<hr>  
105.<h1>标签表单控件</h1>  
106.<form action="http://www.example.com/subscribe.php">  
107.    <label>Age: <input type="text" name="age" /></label>  
108.    <br/ >  
109.    Gender:  
110.    <input id="female" type="radio" name="gender" value="f">  
111.    <label for="female">Female</label>  
112.    <input id="male" type="radio" name="gender" value="m">  
113.    <label for="male">Male</label>  
114.</form>  
115.<hr>  
116.<h1>组合表单元素</h1>  
117.<form action="http://www.example.com/subscribe.php">  
118.    <fieldset>  
119.        <legend>Contact details</legend>  
120.        <label>Email:<br><input type="text" name="email"></label><br>  
121.        <label>Mobile:<br><input type="text" name="mobile"></label><br>  
122.        <label>Telephone:<br><input type="text" name="telephone"></label>  
123.    </fieldset>  
124.</form>  
125.<hr>  
126.<h1>HTML5:表单验证</h1>  
127.<form action="http://www.example.com/login/" method="post">  
128.    <label for="username">Username:</label>  
129.    <input type="text" name="username" id="username" required="required" /><br />  
130.    <label for="password">Password:</label>  
131.    <input type="password" name="password" id="password" required="required" />  
132.    <input type="submit" value="Submit" />  
133.</form>  
134.<hr>  
135.<h1>HTML5:日期</h1>  
136.<form action="http://www.example.com/bookings/" method="post">  
137.    <label for="username">Departure date:</label>  
138.    <input type="date" name="depart" />  
139.    <input type="submit" value="Submit" />  
140.</form>  
141.<hr>  
142.<h1>HTML5:电子邮箱和URL输入控件</h1>  
143.<form action="http://www.example.org/subscribe.php">  
144.    <p>Please enter your email address:</p>  
145.    <input type="email" name="email" />  
146.    <input type="submit" value="Submit" />  
147.</form>  
148.<hr>  
149.<h1>HTML5:搜索输入控件</h1>  
150.</html>  

  

原文地址:https://www.cnblogs.com/max-hou/p/8530716.html