Blogger Information
Blog 7
fans 0
comment 0
visits 2347
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
--表单入门--
东风又西风
Original
263 people have browsed it

表单的格式为lable+input,input内type设置不同的类型


text普通为本框 eamil邮件 password密码 date日期 number数字

<input type="text">

label 里的for的值必须是input内ID的值,才能进行绑定

<lable for="abc">内容</lable><input type="date" id="abc">

  1. <title>表单</title>
  2. </head>
  3. <body>
  4. <!-- action表示表单信息要传递到的文件 -->
  5. <!-- method表示传递的方式是POST"密文传送"或者GET"明文传送" -->
  6. //表示初始化时光标自动在这个文本框内
  7. <!-- required: 必填项, 不写不能提交 -->
  8. <form action="phpcn.php" method="post">
  9. <fieldset style="display: inline-grid; gap: 1em">
  10. <legend>新用户注册</legend>
  11. <!-- label 里的for的值必须是input内ID的值,才能进行绑定 -->
  12. <div class="user">
  13. <label for="user">用户名</label>
  14. <!-- type的值 text 为普通文本框 -->
  15. <input
  16. type="text"
  17. id="user"
  18. name="user"
  19. placeholder="文本输入框内显示"
  20. autofocus
  21. required
  22. />
  23. </div>
  24. <div class="email">
  25. <label for="email">邮箱</label>
  26. <!-- type的值为eamil时为邮箱类型.再提交的时候会进行邮箱的格式验证 -->
  27. <input
  28. type="email"
  29. id="email"
  30. name="email"
  31. placeholder="邮箱输入框内显示"
  32. required
  33. />
  34. </div>
  35. <div class="psw">
  36. <label for="psw">密码</label>
  37. <!-- type 的值为password时为密码类型.输入的时候会以“·”显示 -->
  38. <input
  39. type="password"
  40. id="psw"
  41. name="psw"
  42. required
  43. />
  44. <div class="chusheng">
  45. <label for="chusheng">出生年月</label>
  46. <!-- type的值为date时为日期格式。 -->
  47. <!-- value的值为默认的数据,也会在页面初始化的时候显示出来 -->
  48. <input
  49. type="date"
  50. id="chusheng"
  51. value="2000-01-01"
  52. name="chusheng"
  53. min="1999-12-12"
  54. />
  55. </div>
  56. <div class="sex">
  57. <!-- input.value === input.id === label.for -->
  58. <!-- checked: 布尔属性, 默认选中 -->
  59. <!-- input.type.radio中的 input.name 必须全部相同,因为name是提交互服务器上的变量名 -->
  60. <!-- 只有全部相同,才能保证数据的唯一性 -->
  61. <!-- name=male,female, secret, male, 以最后你选择的那个值为准,只保留一个 -->
  62. <label for="nan">性别</label>
  63. <input type="radio" name="sex" value="nan" id="nan" checked ><label for="nan"></label>
  64. <input type="radio" name="sex" value="nv" id="nv" ><label for="nv"></label>
  65. <input type="radio" name="sex" value="mi" id="mi" ><label for="mi">保密</label>
  66. </div>
  67. <div class="hobby">
  68. <label for="">多选</label>
  69. <input type="checkbox"name="hobby[]" value="aa" id="aa"><label for="aa">aa</label>
  70. <input type="checkbox"name="hobby[]" value="bb" id="bb"><label for="bb">bb</label>
  71. <input type="checkbox"name="hobby[]" value="cc" id="cc"><label for="cc">cc</label>
  72. <input type="checkbox"name="hobby[]" value="dd" id="dd"><label for="dd">dd</label>
  73. </div>
  74. <div class="edu">
  75. <label for="">学历:</label>
  76. <!-- 下拉列表: 从一组预置的值选择一个或多个返回 -->
  77. <!-- 所以,变量的名称与值不在同一个元素上 -->
  78. <!-- name=uname, value=admin
  79. uname = admin
  80. 都声明在 input 一个元素上,名值必须绑定到一个元素上input -->
  81. <!-- <input type="text" name="uname" value="admin" /> -->
  82. <!-- name 和 value 不在一个元素上 -->
  83. <!-- select.name -->
  84. <!-- option.value -->
  85. <select name="edu" id="">
  86. <!-- 提示的制作方式 -->
  87. <!-- <option value="" selected disabled>--请选择--</option> -->
  88. <option value="1">中学</option>
  89. <!-- selected: 默认选中 -->
  90. <option value="2" selected>大学</option>
  91. <option value="2">大学</option>
  92. <option value="3">博士</option>
  93. </select>
  94. </div>
  95. </fieldset>
  96. <button>提交</button>
  97. </form>
  98. </body>
  99. </html>
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:添加一个结果图就更好了
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!