blog/docs/code/html/html-form.md

93 lines
2.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: HTML表单
date: 2022-01-08 23:46:14
tags:
- HTML
categories: HTML
author: Anges黎梦
---
表单用于搜集不同类型的用户输入,表单由不同类型的标签组成,相关标签及属性用法如下:
1、\<form\>标签 定义整体的表单区域
action属性 定义表单数据提交地址
method属性 定义表单提交的方式一般有“get”方式和“post”方式
2、\<label\>标签 为表单元素定义文字标注
3、\<input\>标签 定义通用的表单元素
- type属性
- type="text" 定义单行文本输入框
- type="password" 定义密码输入框
- type="radio" 定义单选框
- type="checkbox" 定义复选框
- type="file" 定义上传文件
- type="submit" 定义提交按钮
- type="reset" 定义重置按钮
- type="button" 定义一个普通按钮
- value属性 定义表单元素的值
- name属性 定义表单元素的名称,此名称是提交数据时的键名
4、\<textarea\>标签 定义多行文本输入框
5、\<select\>标签 定义下拉表单元素
6、\<option\>标签 与\<select\>标签配合,定义下拉表单元素中的选项
注册表单实例:
```html
<form action="http://www..." method="get">
<p>
<label>姓名:</label>
<input type="text" name="username" />
</p>
<p>
<label>密码:</label>
<input type="password" name="password" />
</p>
<p>
<label>性别:</label>
<input type="radio" name="gender" value="0" />
<input type="radio" name="gender" value="1" />
</p>
<p>
<label>爱好:</label>
<input type="checkbox" name="like" value="sing" /> 唱歌
<input type="checkbox" name="like" value="run" /> 跑步
<input type="checkbox" name="like" value="swiming" /> 游泳
</p>
<p>
<label>照片:</label>
<input type="file" name="person_pic">
</p>
<p>
<label>个人描述:</label>
<textarea name="about">
</textarea>
</p>
<p>
<label>籍贯:</label>
<select name="site">
<option value="0">北京</option>
<option value="1">上海</option>
<option value="2">广州</option>
<option value="3">深圳</option>
</select>
</p>
<p>
<input type="submit" name="" value="提交">
<input type="reset" name="" value="重置">
</p>
</form>
```
表单常用样式、属性及示例
- outline 设置input框获得焦点时是否显示凸显的框线一般设置为没有,比如outline:none;
- placeholder 设置input输入框的默认提示文字。
表单布局实例
![](https://limeng-blog.oss-cn-hangzhou.aliyuncs.com/html/search_bar.jpg)