表 单 1

初识表单post和get提交

表单

表单元素格式

例子:

  • form:表单
  • action : 表单提交的位置,可以是网站,也可以是一个请求处理地址
  • method: post/get 提交方式
  • get方式提交:可以再URL中看到我们提交的信息,不安全,高效
  • post :比较安全,传输大文件,
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录注册</title>
</head>
<body>
<h1>注册</h1>
<!--
form 表单
action : 表单提交的位置,可以是网站,也可以是一个请求处理地址
method: post/get 提交方式
  get方式提交:可以再URL中看到我们提交的信息,不安全,高效
  post :比较安全,传输大文件
-->
<form action="first.html" method="post">
    <p>名字:<input type="text" name="username"></p>
    <p>密码:<input type="password" name="pwd"></p>
    <p>
        <input type="submit">
        <input type="reset">
    </p>
</form>
</body>
</html>

输出结果:

(1)get提交

(2)post提交(按住f12在network可以查看密码)


文本框和单选框

例子:

(1)文本框

  • value="haha"    默认初始值
  • maxlength="8"   最长能写几个字符
  • size="30"       文本框的长度

(2)密码框

  • input type="password"

(3)单选框标签

  • input type="radio"
  • value : 单选框的值
  • name: 表示组
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录注册</title>
</head>
<body>
<h1>注册</h1>
<!--
form 表单
action : 表单提交的位置,可以是网站,也可以是一个请求处理地址
method: post get 提交方式
  get 方式提交:可以再URL中看到我们提交的信息,不安全,高效
  post :比较安全,传输大文件
-->
<form action="first.html" method="post">
    <!--

    文本框
    value="haha"    默认初始值
    maxlength="8"   最长能写几个字符
    size="30"       文本框的长度
    -->
    <p>名字:<input type="text" name="username" value="haha" maxlength="8"/></p>
    <!--
    密码框
    input type="password"
     -->
    <p>密码:<input type="password" name="pwd"/></p>
    <!--
    单选框标签
    input type="radio"
    value : 单选框的值
    name: 表示组
    -->
    <p>
        <input type="radio" value="man" name="sex"/>男
        <input type="radio" value="woman" name="sex"/>女
    </p>
    <p>
        <input type="submit"/>
        <input type="reset"/>
    </p>
</form>
</body>
</html>

 输出结果:


按钮和多选按钮

    按钮

  •     input type="button" 普通按钮
  •     input type="image"  图片按钮
  •     input type="submit" 提交按钮
  •     input type="reset"  重置

例子:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录注册</title>
</head>
<body>
<h1>注册</h1>
<!--
form 表单
action : 表单提交的位置,可以是网站,也可以是一个请求处理地址
method: post get 提交方式
  get 方式提交:可以再URL中看到我们提交的信息,不安全,高效
  post :比较安全,传输大文件
-->
<form action="first.html" method="post">
    <!--

    文本框
    value="haha"    默认初始值
    maxlength="8"   最长能写几个字符
    size="30"       文本框的长度
    -->
    <p>名字:<input type="text" name="username" value="haha" maxlength="8"/></p>
    <!--
    密码框
    input type="password"
     -->
    <p>密码:<input type="password" name="pwd"/></p>
    <!--
    单选框标签
    input type="radio"
    value : 单选框的值
    name: 表示组
    -->
    <p>
        <input type="radio" value="man" name="sex"/>男
        <input type="radio" value="woman" name="sex"/>女
    </p>

    <!--
    多选框
    type="checkbox"
    -->
    <p>
        爱好:
        <input type="checkbox" value="sleep" name="hobby"/>睡觉
        <input type="checkbox" value="code" name="hobby"/>敲代码
        <input type="checkbox" value="chat" name="hobby"/>聊天
        <input type="checkbox" value="game" name="hobby"/>游戏
    </p>
    <!--    
    按钮
    input type="button" 普通按钮
    input type="image"  图片按钮
    input type="submit" 提交按钮
    input type="reset"  重置
    -->
    <p>
        按钮:
        <input type="button" value="点击变长" name="but1"/>
        <input type="image" src="../resource/img/5efaffbac96db.jpg"/>
    </p>
    <p>
        <input type="submit"/>
        <input type="reset"/>
    </p>
</form>
</body>
</html>

输出结果:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值