HTML5新增表单元素和表单属性,建议收藏
    		       		warning:
    		            这篇文章距离上次修改已过438天,其中的内容可能已经有所变动。
    		        
        		                
                HTML5引入了一些新的表单控件和表单属性,以下是一些常见的HTML5新增表单元素和属性:
- 色彩选择器 
<input type="color"> - 日期选择器 
<input type="date"> - 时间选择器 
<input type="time"> - 日期时间选择器 
<input type="datetime-local"> - 周选择器 
<input type="week"> - 月份选择器 
<input type="month"> - 搜索框 
<input type="search"> - 电话号码 
<input type="tel"> - 数字 
<input type="number"> - 范围 
<input type="range"> - email 
<input type="email"> - 网址 
<input type="url"> - 必填(
required属性) - 模式验证(
pattern属性) - 插槽显示(
placeholder属性) - 自动对焦(
autofocus属性) - 只读(
readonly属性) - 禁用(
disabled属性) - 多个选项同时选择(
multiple属性) 
示例代码:
<form>
  <label for="username">用户名:</label>
  <input type="text" id="username" name="username">
 
  <label for="bio">简历:</label>
  <input type="text" id="bio" name="bio" placeholder="输入简历">
 
  <label for="birthday">生日:</label>
  <input type="date" id="birthday" name="birthday">
 
  <label for="email">电子邮件:</label>
  <input type="email" id="email" name="email" required>
 
  <label for="phone">电话号码:</label>
  <input type="tel" id="phone" name="phone" pattern="[0-9]{3}-[0-9]{2}-[0-9]{3}">
 
  <label for="password">密码:</label>
  <input type="password" id="password" name="password">
 
  <label for="photo">照片:</label>
  <input type="file" id="photo" name="photo">
 
  <input type="submit" value="提交">
</form>这个示例展示了如何在HTML5中使用不同的新表单元素,以及如何使用placeholder、required、pattern等属性来增强表单验证和用户体验。
评论已关闭