表单的作用:收集用户信息
1.表单域/表单框
标签名称:form 没有实际含义 就是一个大盒子为了收集用户信息进行提交保存起来
属性
- action 表示接后台地址
- name 表示表单的名称(了解)
- method 表示与后台交互的方法 GET/POST
- 表示与后台做数据交互
- get请求的时候 参数会显示在地址栏上 post不会
- post相对来说比get安全(前端是没有绝对安全的)
2.表单控件
标签名称: input 单标签
属性
① 了解
- name 表单控件的名称(了解)
- size 表示表单控件的长度(字符数)
- maxlength 最大长度(手机号码)
② 重要
- type 类型 控制当前表单控件的作用 默认是文本输入框 密码框、单选框、多选框、提交按钮、重置按钮
- value 价值 表示提示文本 跟随不同的type属性值 作用发生不同的改变。.
<body>
<form action="php.php" name="个人相亲表">
<input type="text" maxlength="11">
</form>
</body>
效果图:
表单中重要的属性设置
input中的type和value的使用(HTML4)
- type的默认值是text 表示文本输入框 value是提示文本 用户输入的时候需要手动的删除文本提示
- password 密码框 黑色的实心圆 value是占位置的(HTML5版本中新增了一个属性 placeholder占位符)
- radio 单选按钮 设置name属性值 属性值相同的即可
- checkbox 多选按钮
功能按钮
- submit 提交 使用value (必须放在form表单框中) ?表示后面接参数
- reset 重置 点击可以清空当前表单控件中所有内容 (必须放在form表单框中)
特殊的按钮:空按钮
- 第一种 type的属性值button 需要绑定js事件
- 第二种 button标签 默认会提交刷新页面
高级用法
1.下拉列表/菜单 select>option
2.多行文本域 textarea 建议/意见 禁止用户拖拽 设置css属性 resize:none
3.上传文件 type的属性值 file文件类型
4.隐藏标签 type的属性值 hidden隐藏
表单标签
- fieldset 表单框 表单字段集 和form作用相似
- legend 字段级标题
- label 信息提示标签 绑定关系 性别的文字也可以点击进行切换
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<input type="color">
<input type="date">
<input type="time">
<input type="number" name="price">
<input id="avatar" type="file" style="display: none;">
<label for="avatar">
<!-- <img src="./abc.png" alt=""> -->
</label>
<label for="select">选择</label>
<input type="checkbox" id="select">
<form action="">
<!-- name 属性表示提交的时候提交我自己 -->
<!-- 提交格式叫做 查询字符串格式(query string) 字段名=值 -->
<!-- name 属性的值就是字段名, 用户书写的内容就是 值 -->
<label for="u">用户名:</label>
<!-- 关掉自动补全 -->
<!-- <input id="u" type="text" name="username" autocomplete="off"> <br> -->
<!-- 开启自动获取焦点 -->
<input id="u" type="text" autofocus name="username" autocomplete="off"> <br>
<label>
密码: <input type="text" autofocus> <br>
</label>
<!-- <input type="submit"> -->
<!-- <input type="button" value="按钮"> -->
<!-- 因为在 form 标签内, 所以是 提交按钮 -->
<!-- <button>按钮</button> -->
<button type="button">按钮</button>
</form>
<!-- type=file 是文件选择 -->
<!-- 默认只能选择一个文件 -->
<!-- 当 type=file 标签有了 multiple 属性以后, 可以进行多文件选择 -->
<!-- multiple 是一个布尔类型属性, 只要有属性名就够了 -->
<input type="file" multiple>
<!-- label 标签的两种使用方式 -->
<!-- 方式 1 -->
<!-- label 标签和 for 属性和 input 标签的 id 属性配套 -->
<!-- 方式 2 -->
<!-- label 标签包裹 input 标签 -->
<!-- select -->
<select>
<!-- 北京: 表示的是展示在页面上的值 -->
<!-- bj: 是当你选中这一项的时候, select 标签的 选中值 -->
<option value="bj">北京</option>
<option value="sh">上海</option>
<option value="sz" selected>深圳</option>
<option value="gz">广州</option>
<option value="cx">曹县</option>
</select>
<select multiple>
<option value="bj">北京</option>
<option value="sh" selected>上海</option>
<option value="sz">深圳</option>
<option value="gz" selected>广州</option>
<option value="cx">曹县</option>
</select>
<textarea name="" id="" cols="30" rows="10"></textarea>
</body>
</html>