html表单


表单
场景:在网页中显示收集用户信息的表单效果,如登录页、注册页
通过创建表单

属性作用
name表单名称
action规定当提交表单时向何处发送表单数据
method规定提交数据的方式
get获取数据;post发送数据

(1)input系列

input标签而已通过type属性值的不同,展示不同效果

type属性效果
text单行文本
password密码框
radio单选框
checkbox多选框
file选择文件
submit提交按钮
reset重置按钮
button普通按钮,默认无功能,之后配合js添加功能

A.单行文本/密码框

属性作用
placeholder用于提示用户输入的文本
required不能输入为空
autofocus自动获得光标
value输入框的内容
<input type="text">

效果:在这里插入图片描述

<input type="text" placeholder="请输入姓名">

效果:在这里插入图片描述

<form action="">
    <input type="text" required>
    <button type="submit">注册</button>
</form>

效果:在这里插入图片描述

<input type="text" autofocus>

效果:在这里插入图片描述

效果:在这里插入图片描述

效果:![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/15913b42103f47e3b4a88478f7c90935.png) ## B.单选框/复选框
属性作用
name分组(相同name属性的单选框为一组)
checked默认选中
<input type="radio">语文
<input type="radio">数学
<input type="radio">英语
<input type="radio">政治

效果:在这里插入图片描述

<input type="radio" name="kemu">语文
<input type="radio" name="kemu">数学
<input type="radio" name="kemu">英语
<input type="radio" name="kemu">政治

效果:在这里插入图片描述

<input type="radio" name="kemu">语文
<input type="radio" name="kemu">数学
<input type="radio" name="kemu">英语
<input type="radio" name="kemu" checked>政治

效果:在这里插入图片描述

<input type="checkbox" checked>我同意<a href="https://www.baidu.com" target="_blank">注册条款</a>

效果:在这里插入图片描述

C.选择文件

属性作用
multiple多文件选择
<input type="file">

效果:(只可以选中一个文件)
在这里插入图片描述
在这里插入图片描述

<input type="file" multiple>

效果:在这里插入图片描述
在这里插入图片描述

D.按钮(不常用)

属性作用
value设置按钮文本
注意:如果需要实现按钮功能,需要配合form标签使用
form使用方法:用form标签把表单标签一起包裹起来即可
<form action="">
      姓名:<input type="text" placeholder="请输入姓名" />
      <br />
      密码:<input type="password" placeholder="请输入密码" />
      <br />
      <input type="file" />
      <br />
      <input type="submit" />
<input type="reset" />
 </form>

效果:(第二个是点击了重置选项的)
在这里插入图片描述
在这里插入图片描述



效果:在这里插入图片描述

图片按钮

效果:在这里插入图片描述

(2)button按钮(常用)

特定:button标签是双标签,可以方便放在文本中显示
注意:谷歌浏览器中button默认是提交按钮

属性(同input系列中按钮)效果
submit提交按钮
reset重置按钮
button普通按钮,默认无功能,之后配合js添加功能
<button>提交</button>
<button type="reset">重置</button>
<button type="button">普通按钮</button>

效果:在这里插入图片描述

<p>affhgjk<button>提交</button>gfjhkh</p>

效果:在这里插入图片描述

(3)select下拉菜单

场景:在网页中提供多个选择项的下拉菜单表

属性效果
selected默认选中
标签组成:
标签名作用
select下拉菜单的整体
option下拉菜单的每一项
<select name="" id="">
        <option>5</option>
        <option>6</option>
        <option>7</option>
</select>

效果:在这里插入图片描述

<select name="" id="">
        <option>5</option>
        <option selected>6</option>
        <option>7</option>
</select>

效果:在这里插入图片描述

(4)textarea文本域

场景:在网页中提供多行文本的表单控件
注意:右下角可以拖拽改变大小(通过css禁用)

属性效果
cols文本域内可见宽度
rows文本域内可见行数

效果:在这里插入图片描述

(5)label

场景:用于绑定内容于表单标签的关系

方法步骤
1label标签把内容包起来,表单标签添加id属性;for设置与id相同
2用label标签把内容和表单标签包裹起来;删除label标签的for属性

方法1:<input type="radio" name="kemu" id="1"/> <label for="1">男</label>
方法2:<label >女
效果:在这里插入图片描述

这样实现了只点击文本“男、女”不点击单选框也可以选中

表格式表单

在这里插入图片描述

<table align="center">
    <caption><h2>请填写个人信息</h2></caption>
    <tr>
      <td>用户名:</td>
      <td><input type="text"></label></td>
    </tr>
    <tr>
      <td>所在地区:</td>
      <td><input type="text" placeholder="北京"></td>
    </tr>
    <tr>
      <td>密码:</td>
      <td><input type="password"></td>
    </tr>
    <tr>
      <td>性别:</td>
      <td>
        <label><input type="radio" name="sex"></label>
        <label><input type="radio" name="sex"></label>
      </td>
    </tr>
    <tr>
      <td>爱好:</td>
      <td>
      <label><input type="checkbox" name="habbit">听歌</label>
      <label><input type="checkbox" name="habbit">跳舞</label>
      <label><input type="checkbox" name="habbit">运动</label>
      </td>
    </tr>
    <tr>
      <td>上传图像:</td>
      <td><input type="file" value="选择文件"></td>
    </tr>
    <tr>
      <td></td>
      <td>
        <button type="button">注册</button>
        <button type="submit">提交</button>
        <button type="reset">重置</button>
        <input type='image' src="./btnimg.png">
      </td>
    </tr>
    <tr>
      <td>给我留言:</td>
      <td><textarea name="" id="" cols="30" rows="10"></textarea></td>
    </tr>
    <tr>
      <td>出生年月:</td>
      <td>
        <select name="" id="">
          <option value="">选择年份</option>
        </select>
        <select name="" id="">
          <option value="">选择月份</option>
        </select>
      </td>
    </tr>
    <tr>
      <td>籍贯:</td>
      <td>
        <select name="" id="">
          <option value="">上海</option>
        </select>
      </td>
    </tr>
  </table>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值