博主信息
博文 6
粉丝 0
评论 1
访问量 6490
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
按钮,下拉框,文本域,表单域元素的学习
云猫
原创
1765人浏览过

1. 表单和按钮<button>

属性 描述
type 值为 submit 是提交按钮;值为 button 是可点击按钮;值为 reset 是重置按钮
value 初始指定值
disabled 禁用按钮
formaction 可强制设置 form 的 action 属性值
formmethod 可强制设置 form 的 method 属性值 即访问方式
formtarget 可强制设置表单提交新窗口打开
form 按钮加这个属性可在表单外,通过表单 ID 绑定表单,随表单一起提交到服务器
  • 示例代码
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <form action="login.php" id="myform" method="GET">
  10. <section>
  11. <label for="username">账号:</label
  12. ><input type="text" name="username" id="username" />
  13. </section>
  14. <section>
  15. <label for="password">密码:</label
  16. ><input type="password" name="password" id="password" />
  17. </section>
  18. <button type="submit">登录</button>
  19. <button type="reset" form="myform">重置</button>
  20. </form>
  21. </body>
  22. </html>

2. 下拉框

标签/属性 描述
<select>...</select> 定义一个下拉框
<option>...</option> 定义一个下拉框的表项值
<optgroup>...</optgroup> 对下拉框表项值进行分组
size="10" 作用在 select 标签中,意思是展示多少个表项
label="xx" 作用在 optgroup 标签中,意思是对分组进行命名
  • 示例代码
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>下拉框</title>
  7. </head>
  8. <body>
  9. <form action="">
  10. <select name="" id="" size="10">
  11. <optgroup label="省份">
  12. <option value="">广东</option>
  13. <option value="">湖北</option>
  14. <option value="">北京</option>
  15. <option value="">上海</option>
  16. </optgroup>
  17. <optgroup label="市级">
  18. <option value="">武汉</option>
  19. <option value="">广州</option>
  20. <option value="">合肥</option>
  21. <option value="">宁波</option>
  22. </optgroup>
  23. </select>
  24. </form>
  25. </body>
  26. </html>

3. 多行文本域

标签/属性 描述
<textarea>...</textarea> 定义一个文本域
cols 文本域宽度
rows 文本域高度
form 绑定表单
minlength 限制最小长度
maxlength 限制最大长度
  • 示例代码
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>文本域</title>
  7. </head>
  8. <body>
  9. <form action="" id="myform"></form>
  10. <textarea
  11. name="myformtext"
  12. id="myformtext"
  13. cols="60"
  14. rows="10"
  15. minlength="6"
  16. maxlength="100"
  17. form="myform"
  18. ></textarea>
  19. </body>
  20. </html>

4.0 表单分组

标签/属性 描述
<fieldset>...</fieldset> 定义一个表单分组
<legend>...</legend> 定义一个表单分组的名称
  • 示例代码
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>表单分组</title>
  7. </head>
  8. <body>
  9. <form action="">
  10. <fieldset>
  11. <legend>账户信息</legend>
  12. <section>
  13. <label for="">账号:</label> <input type="text" id="username" />
  14. </section>
  15. <section>
  16. <label for="">密码:</label> <input type="password" id="password" />
  17. </section>
  18. </fieldset>
  19. <fieldset>
  20. <legend>其他信息</legend>
  21. <section>
  22. <label for="">邮箱:</label> <input type="email" id="email" />
  23. </section>
  24. <section>
  25. <label for="">电话:</label> <input type="tel" id="tel" />
  26. </section>
  27. </fieldset>
  28. </form>
  29. </body>
  30. </html>

总结

  • 通过本节课学习,已经基本掌握表单的常用组件知识!
批改老师:天蓬老师天蓬老师

批改状态:合格

老师批语:表单中的一些属性, 你在其它地方可能从未看到过, 好好学
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学