HTML(十)表单内容

表单这部分是网页上的一个重点,实际应用中有很多地方都用到了表单,下面大概介绍以下表单的流程,具体请看下一章节;

表单的使用过程大致有:构建表单-》配置表单-》验证表单-》服务器处理

 

构建表单

所有的表单都是from组成的(注意,按钮只可以是button

<form>
    <div><label>姓名:<input></label></div>
    <div><label>电话:<input type="tel"></label></div>
    <div><label>邮箱:<input type="email"></label></div>
    <fieldset>
        <legend>披萨大小</legend>
        <input type="radio" name="size">小
        <input type="radio" name="size">中
        <input type="radio" name="size">大

    </fieldset>

    <fieldset>
        <legend>披萨配料</legend>
        <label><input type="checkbox">熏肉</label>
        <label><input type="checkbox">奶酪</label>
        <label><input type="checkbox">洋葱</label>
        <label><input type="checkbox">蘑菇</label>
    </fieldset>

    <div>
        <label>配送时间:<input type="time" min="11:00" max="21:00" step="900"></label>
    </div>
    <div>
        <button >提交</button>
    </div>

</form>

 

服务器处理接口

假设服务器需要用到的数据信息如下

-https://pizza.example.com/order

-application/x-www-form-urlencoded

-custname,custtel,custemail,size,topping,delivery

 

表单配置

把提交类型,属性,地址等信息加入表单,radio和chekbox因为name值是相同的,所以用value区分

<form method="post" 

           enctype="application/x-www-form-urlencoded" 

           action="https://pizza.example.com/order">

    <div><label>姓名:<input name="custname"></label></div>
    <div><label>电话:<input type="tel" name="custtel"></label></div>
    <div><label>邮箱:<input type="email" name="custemail"></label></div>
    <fieldset>
        <legend>披萨大小</legend>
        <input type="radio" name="size" value="small">小
        <input type="radio" name="size" value="medium">中
        <input type="radio" name="size" value="large">大
    </fieldset>
    <fieldset>
        <legend>披萨配料</legend>
        <label><input type="checkbox" name="topping" value="bacon">熏肉</label>
        <label><input type="checkbox" name="topping" value="cheese">奶酪</label>
        <label><input type="checkbox" name="topping" value="onion">洋葱</label>
        <label><input type="checkbox" name="topping" value="mushroom">蘑菇</label>
    </fieldset>
    <div>
        <label>配送时间:<input type="time" min="11:00" max="21:00" step="900" name="delivery"></label>
    </div>
    <div>
        <button >提交</button>
    </div>

</form>

 

验证表单

通常一些简单的校验会在表单提交之前有前端做简单的校验,为表单的项加上required就可以了

<form method="post" enctype="application/x-www-form-urlencoded" action="https://pizza.example.com/order">
    <div><label>姓名:<input name="custname" required></label></div>
    <div><label>电话:<input type="tel" name="custtel" required></label></div>
    <div><label>邮箱:<input type="email" name="custemail" required></label></div>
    <fieldset>
        <legend>披萨大小</legend>
        <input type="radio" name="size" value="small" required>小
        <input type="radio" name="size" value="medium">中
        <input type="radio" name="size" value="large" >大
    </fieldset>
    <fieldset>
        <legend>披萨配料</legend>
        <label><input type="checkbox" name="topping" value="bacon" required>熏肉</label>
        <label><input type="checkbox" name="topping" value="cheese">奶酪</label>
        <label><input type="checkbox" name="topping" value="onion">洋葱</label>
        <label><input type="checkbox" name="topping" value="mushroom">蘑菇</label>
    </fieldset>
    <div>
        <label>配送时间:<input type="time" min="11:00" max="21:00" step="900" name="delivery"></label>
    </div>
    <div>
        <button >提交</button>
    </div>
</form>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Oliver尹

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值