伴随着互联网富应用以及移动开发的兴起,传统的Web表单已经越来越不能满足开发的需求,HTML5在Web表单方向也做了很大的改进,如拾色器、日期/时间组件等,使表单处理更加高效。

1.1新增表单类型

- email - 限定输入内容为邮箱地址,表单提交时会校验格式
- url - 限定输入内容为URL,表单提交时会校验格式
- number - 限定输入内容为数字,表单提交时会校验格式
- range - 数值范围选择器
- Date Pickers - 日期时间选择器
+ 样式不能修改,移动端用的比较多,因为移动端显示的是系统的时间或日期选择器
+ date - 选取日、月、年
+ month - 选取月、年
+ week - 选取周和年
+ time - 选取时间(小时和分钟)
+ datetime - 选取时间、日、月、年,浏览器兼容性不好,效果等同于datetime-local
+ datetime-local - 选取本地时间、日、月、年
- search - 搜索域,语义化,表示定义搜索框

代码:

<form action="">
<fieldset>
<legend>表单类型</legend>
<label for="">
email: <input type="email" name="email" required>
</label>
<label for="">
color: <input type="color" name="color">
</label>
<label for="">
url: <input type="url" name='url'>
</label>
<label for="">
<!-- step 步数-->
number: <input type="number" step="3" name="number">
</label>
<label for="">
range: <input type="range" name="range" value="20">
</label>
<label for="">
search: <input type="search" name="search">
</label>
<label for="">
tel: <input type="tel" name="tel">
</label>
<label for="">
time: <input type="time" name="time">
</label>
<label for="">
date: <input type="date" name="date">
</label>
<label for="">
datetime: <input type="datetime">
</label>
<label for="">
week: <input type="week" name="week">
</label>
<label for="">
month: <input type="month" name="month">
</label>
<label for="">
datetime-local: <input type="datetime-local" name="datetime-local">
</label>
<input type="submit">
</fieldset>
</form>

其他常用旧表格类型:

<form action="">
<input type="text"/>
<input type="button"/>
<input type="submit"/>
<input type="checkbox"/>
<input type="radio"/>
<input type="password"/>
<input type="file"/>
<input type="image"/>
<input type="reset"/>
</form>

1.2新增表单属性

- form
+ autocomplete 设置整个表单是否开启自动完成 on|off
+ novalidate 设置H5的表单校验是否工作 true 不工作 不加该属性代表校验

- input:
+ autocomplete 单独设置每个文本框的自动完成
+ autofocus 设置当前文本域页面加载完了过后自动得到焦点
+ form 属性是让表单外的表单元素也可以跟随表单一起提交
+ form overrides
* formaction 在submit上重写表单的特定属性,当点击当前submit时会以当前值使用
* formenctype,
* formmethod,
* formnovalidate,
* formtarget
+ list 作用就是指定当前文本框的自动完成列表的数据 datalist 在界面上是看不见的,只是用于定义数据列表的
+ min / max / step
* min max 限制值的范围,但是不会再输入时限制,提交时校验,
* step设置的是每次加减的增量
* 主要使用在number range datepicker上
+ multiple
* 文本域的多选
+ pattern
* 设置文本框的匹配格式(正则)
+ placeholder
* 文本框占位符
+ required
* 限制当前input为必须的

代码:

 <form action="" autocomplete="on" id="form" >
<fieldset>
<legend>表单属性</legend>
<label for="">
autofocus: <input type="text" autocomplete="on" name="autofocus" autofocus required>
</label>
<label for="">
placeholder: <input type="text" pattern="\D+" placeholder="这是一个占位符" novalidate>
</label>
<label for="">
multiple: <input type="file" multiple>
</label>
<input type="submit" value="提交">
</fieldset>
</form>
<label for="">
表单外的一个元素:
<input type="text" name="outer" form="form">
</label>

1.3表单事件

oninput 用户输入内容时触发,可用于移动端输入字数统计
oninvalid 验证不通过时触发 setCustomValidity 设置自定义提示

代码:

     <form action="">
<fieldset>
<legend>表单事件</legend>
<label for="">
oninput: <input type="email" id="input">
</label>
<input type="submit" value="提交">
</fieldset>
</form>
<script>
var input = document.getElementById('input'); input.oninvalid = function () { this.setCustomValidity('请输入正确的邮箱地址')
}
</script>

1.4移动端虚拟键盘调用

   <input type="text" name="txt_text" id="txt_text">
<input type="number" name="txt_number" id="txt_number">
<input type="email" name="txt_email" id="txt_email">
<input type="tel" name="txt_tel" id="txt_tel">
<input type="url" name="txt_url" id="txt_url">

H5 表单的更多相关文章

  1. H5表单

    H5表单 HTML5 新的 Input 类型 HTML5 拥有多个新的表单输入类型.这些新特性提供了更好的输入控制和验证. 本章全面介绍这些新的输入类型: email url number range ...

  2. 基于react hooks,zarm组件库配置开发h5表单页面

    最近使用React Hooks结合zarm组件库,基于js对象配置方式开发了大量的h5表单页面.大家都知道h5表单功能无非就是表单数据的收集,验证,提交,回显编辑,通常排列方式也是自上向下一行一列的方 ...

  3. H5表单基础知识(二)

    表单新增属性 <!--<input type="text" class="name" />--> <!-- placeholder ...

  4. [H5表单]一些html5表单知识及EventUtil对象完善

    紧接着上面的文章,一开始准备一篇文章搞定,后来看到,要总结的东西还不少,干脆,把上面文章拆成两部分吧,这部分主要讲讲表单知识! 表单知识 1.Html5的autofocus属性. 有个这个属性,我们不 ...

  5. h5表单属性的介绍

    表单 type属性对应的属性值 text:代表文本框 案例:<input type="text" /> password:代表密码框 radio:单选框 checkbo ...

  6. H5: 表单验证失败的提示语

    前言     前端的童鞋在写页面时, 都不可避免的总会踩到表单验证这个坑. 这时候, 我们就要跪了, 因为要写一堆js来检查. 但是自从H5出现后, 很多常见的表达验证, 它都已经帮我们实现了, 让我 ...

  7. H5——表单验证新特性,注册模态框!

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  8. H5 表单元素

    HTML5 表单元素 HTML5 的新的表单元素: HTML5 拥有若干涉及表单的元素和属性. 本章介绍以下新的表单元素: datalist keygen output 浏览器支持 Input typ ...

  9. [H5表单]html5自带表单验证体验优化及提示气泡修改

    慕课网之前录制的视频,js/jquery各种宽高的理解和应用,最近终于上线了.还有一个html5左侧导航没有上线!最近慕课网系列课程让我录制一个html5表单验证的课程.今天就稍微说一下表单验证!另外 ...

随机推荐

  1. KAOS模型

    问题描述: 我们开发了一种针对时序数据的文件格式TSFile,本身不支持sql查询.为了让公司分析人员能够用SQL进行分析,并且应用一些机器学习算法进行预测,需要设计并实现一个TSFile与Spark ...

  2. 【笔记】mysql两条数据的某个属性值互换

    update groupuser as g1 join groupuser as g2 on (g1.user_id=1 and g2.user_id = 2) or(g1.user_id = 2 a ...

  3. ubuntu 报错: The system is running in low-graphics mode

    出错原因不知为何,apt-get install --reinstall unity-greeter 不起作用. 试了一下,这样居然有效: cd /etc/X11 sudo cp xorg.conf. ...

  4. log4net配置

    1.configuration配置 <configSections> <section name="log4net" type="log4net.Con ...

  5. C语言的可变参数在Linux(Ubuntu)与Windows下注意点

    基本上C语言的可变参数原理在不同平台和不同编译器下基本类似(通过函数入栈,从右向左,从高位到低位地址),不过部分实现会有所不同:在使用中需要注意的是: va_list 为char 类型指针,部分调用如 ...

  6. Duilib源码分析(三)XML解析器—CMarkup

    上一节介绍了控件构造器CDialogBuilder,接下来将分析其XML解析器CMarkup: CMarkup:xml解析器,目前内置支持三种编码格式:UTF8.UNICODE.ASNI,默认为UTF ...

  7. 解决一则enq: TX – row lock contention的性能故障

    上周二早上,收到项目组的一封邮件: 早上联代以下时间点用户有反馈EDI导入"假死",我们跟踪了EDI导入服务,服务是正常在跑,可能是处理的慢所以用户感觉是"假死" ...

  8. Git使用笔记

    Ubuntu下安装步骤 sudo apt-get install git完成git的安装 安装完成后进行配置 git config –global user.name “Your Name” git ...

  9. Console app 里的依赖注入及其实例生命周期

    依赖注入是 ASP.NET Core 里的核心概念之一,我们平常总是愉快地在Startup类的ConfigureServices方法里往IServiceCollection里注册各种类型,以致有一些同 ...

  10. Fiddler问题 - creation of the root certificate was not successful

    打开cmd执行命令. d: cd D:\soft\Fiddler2 makecert.exe -r -ss my -n "CN=DO_NOT_TRUST_FiddlerRoot, O=DO_ ...