HTML 表单的用法

2017-05-20  本文已影响0人  yangjie727

1. 简介

HTML表单是一个包含表单元素的区域,用来收集用户输入的内容并提交。

表单元素通常包括文本域(textarea)单选框(radio-buttons)复选框(checkboxes)等。

表单使用标签<form></form>来设置

<form>的常用属性

action:表单提交的地址

method:提交表单的方法,有get和post两种。

<form action="/getInfo" method="post"></form>

2. 常用表单元素

大多数情况下被用到的表单标签有

<input>,<textarea>多行文本框,<option>下拉框,<lable>input的标注等

常用属性:

type:输入的类型

name:表单的名称

value:表单的内容

文本域(Text Fields)

文本域通过<input type="text">标签来设定,当用户要在表单中键入用户名、邮箱等少量内容时,就会用到文本域。

<lable>标签用于对<input>的注释,通常配合for属性使用。与id属性相对应。

例如

<form action="/getInfo"method="get">

<lable for="username">姓名:</lable>

<input type="text" name="usernme" id="username">

</form>

密码字段

通过标签<input type="password">来定义

<form action="#" method="post">

<lable for="password">密码:</lable>

<input type="password" id="password" name="password">

</form>

单选框(Radio buttons)

通过标签<input type="radio">来定义

<form action="#" method="post">

<lable>性别:</lable>

<input type="radio" name="sex" value="good">好

<input type="radio" name="sex" value="bad">坏

</form>

复选框(Checkboxes)

通过标签<input type="checkbox">来定义

<form action="#" method="post">

<input type="checkbox"name="hobby"value="read">读书

<input type="checkbox"name="hobby"value="music">听歌

<inputtype="checkbox"name="hobby"value="study">学习

</form>

提交按钮(Submit Button)

通过<input type="submit">定义

当用户点击提交按钮时,表单的内容会被传送。传送的方式和目的地由标签定义。

<form action="/getInfo"method="get">

<inputtype="submit"value="Submit"/>提交

</form>

上一篇 下一篇

猜你喜欢

热点阅读