博客列表 >0404 表单

0404 表单

Mryang的博客
Mryang的博客原创
2020年04月06日 12:06:38755浏览

0404 表单

1.在<form>标签外面写表单元素

  1. <h3>用户注册</h3>
  2. <form action="register.php" id="regitser">
  3. <!-- 图像域 -->
  4. <input type="image" type="submit" src="button.png" width="100" />
  5. </form>
  6. <hr />
  7. <section>
  8. <label for="email">邮箱</label>
  9. <input type="email" name="email" id="register" form="regitser" />
  10. </section>
  11. <section>
  12. <label for="age">年龄</label>
  13. <input type="number" nama="age" min="18" max="30" id="age" form="regitser" value="20" step='5' />
  14. </section>

效果以及提交后的值

2.formaction属性可以将数据提交到不同的脚本

  1. <h3>登录/注册</h3>
  2. <form>
  3. <section>
  4. <label for="username">姓名:</label>
  5. <input type="text" name='username' id='username' required autofocus>
  6. </section>
  7. <section>
  8. <label for="password">密码:</label>
  9. <input type="password" name='password' id='password' required>
  10. </section>
  11. <section>
  12. <button formaction="login.php" formmethod="POST" formtarget="_blank">登录</button>
  13. <button formaction="register.php" formmethod="get" formtarget="_blank">注册</button>
  14. </section>
  15. </form>

3.下拉列表

  1. <form action="">
  2. <section>
  3. <select name="lang" id="lang" size='8' multiple onchange="alert(this.value)" onclick="alert(this.value)">
  4. <optgroup label="前端">
  5. <option value="HTML5">HTML5</option>
  6. <option value="CSS3" selected>CSS3</option>
  7. <option value="JavaScript">JavaScript</option>
  8. </optgroup>
  9. <optgroup label="后端">
  10. <option value="PHP" label="PHP">
  11. <option value="MYSQL" label="MYSQL">
  12. <option value="laravel" label="laravel">
  13. </optgroup>
  14. </select>
  15. </section>
  16. </form>

4.文本域

  1. <form action="">
  2. <section>
  3. <textarea name="content" id="content" cols="30" rows="10" placeholder="内容少于50字" minlength="5" maxlength="50"
  4. onselect="this.style.color='red'">你好</textarea>
  5. <button type="submit" formaction="register.php" formmethod="POST">提交</button>
  6. </section>
  7. </form>

5.表单域分组元素

  1. <form action="" id='register'></form>
  2. <fieldset name='base' form='register'>
  3. <legend>基本信息</legend>
  4. <section>
  5. <label for="email">邮箱:</label>
  6. <input type="email" name="email" id="email" placeholder="您的邮箱" form='register' autofocus>
  7. </section>
  8. <section>
  9. <label for="password1">密码:</label>
  10. <input type="password" name="password1" id="password1" placeholder="密码" form='register'>
  11. </section>
  12. <section>
  13. <label for="password2">重复密码:</label>
  14. <input type="email" name="password2" id="password2" placeholder="重复密码" form='register'>
  15. </section>
  16. </fieldset>
  17. <fieldset name='extend' form='register'>
  18. <legend>选填信息</legend>
  19. <section>
  20. <label for="nickname">昵称:</label>
  21. <input type="text" name="nickname" id="nickname" placeholder="昵称" form='register'>
  22. </section>
  23. <section>
  24. <label for="age">年龄:</label>
  25. <input type="number"" name=" age" id="age" placeholder="年龄" form='register'>
  26. </section>
  27. </fieldset>
  28. <button type="submit" form="register">提交</button>

6.总结

这节课的收获就是表单的formaction属性,可以提交到不同的后台脚本,这个之前没见过也没用过。目前为止html就学完了,重点就学了html5的代码规范、表格、表单这些。感觉内容比较少也比较简单,当然是因为时间紧。我希望后台框架、数据库优化等知识可以详细的讲解。

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议