input标签,新增那些属性

news/2024/7/23 10:06:46 标签: input, HTML, html5

input标签作为页面与用户交互的重要入口,了解掌握input的属性,至为重要。

type属性

HTML5给input表现的type属性,添加了很多的属性值,用来丰富了文本框类型。比如:

<body>
    <input type="email" name="" id="">
    <input type="button" value="">
    <input type="checkbox" name="" id="">
    <input type="color" name="" id="">
    <input type="date" name="" id="">
    <input type="datetime" name="" id="">
    <input type="datetime-local" name="" id="">
    <input type="radio" name="" id="">
    <input type="range" name="" id="">
    <input type="url" name="" id="">
    <input type="time" name="" id="">
    <input type="month" name="" id="">
    <input type="week" name="" id="">
    <input type="search" name="" id="">
    <input type="number" name="" id="">
    <input type="tel" name="" id="">
</body>

如果是H5页面的话,在不同的手机会有不同的展示,比如:

在这里插入图片描述

在这里插入图片描述
唤醒的手机本身的输入的效果。

文件上传

input标签上传文件的话,type属性为file,然后根据不同的场景,设置不同的属性。比如:

1、 accept属性,限制上传文件的类型,比如image/png和image/gif表示只能上传图片类型,并且扩展名是png或gif。image/*表示任何图片类型的文件。当然,accept属性也支持.xx,表示扩展名标识的限制,例如accept=“.pdf,.doc”。在手机上预览的话,会提示从相册选择图片还是调用相机;

2、multiple属性,表示是否同时上传多个文件;
3、capture属性,该属性可以调用系统默认相机、摄像机和录音功能,同时还有其他取值:
 capture="camera"表示相机。
 capture="camcorder"表示摄像机。
 capture="microphone"表示录音。
使用如下:

<body>
    <p><input type="file" multiple accept="image/*"></p>
    <p><input type="file" multiple accept="image/*" capture="camera"></p>
    <p><input type="file" accept="audio/*" capture="microphone"></p>
    <p><input type="file" accept="video/*" capture="camcorder" id="uploader"></p>

    <script>
        const recorder = document.getElementById("uploader");
        recorder.addEventListener("change",function(e){
            const file = e.target.files;
        })
    </script>
</body>

autofocus属性

autofocus属性设置为true,在页面加载时,会自动获取焦点。

min和max属性

min和max属性规定了input标签的最大值和最小值,min和max属性适用的输入类型:number、range、date、month、time以及week。

pattern属性

pattern属性用于检查标签内容值的正则表达式。适用于以下输入类型:text、search、url、tel、email和password

required属性

设置了该属性,在表单提交的时候,会校验required属性为true的字段,适用于text、search、url、tel、email、password、number、checkbox、radio和file。


http://www.niftyadmin.cn/n/5024649.html

相关文章

Linux服务器——进程/线程池

进程/线程池 动态创建子进程/线程的缺点&#xff1a; 比较耗时&#xff0c;这将导致较慢的客户响应&#xff1b;动态创建的子进程/线程通常只是用来为一个客户服务&#xff0c;这将导致系统上产生大量的细微进程/线程。进程/线程之间的切换将消耗大量 CPU 时间&#xff1b;动…

Kotlin 协程 - 协程异常处理器 CoroutineExceptionHandler

一、异常的传播 Job的取消和异常传播是双向的&#xff08;结构化并发&#xff09;&#xff0c;如果异常在局部没有捕获处理而被协程抛出&#xff0c;该协程会先cancel所有子协程再cancl自己&#xff0c;如果这个异常是 CancellationException 类型便终止向上传播&#xff0c;如…

MYSQL:Select语句顺序

SELECT子句及其顺序整理表格&#xff1a; 子句 说明是否必须使用SELECT 要返回的列或表达式是FROM 从中检索数据的表仅在从表选择数据使用WHERE 行级过滤否GROUP BY 分组说明仅在按组计算聚…

阿里云服务器部署安装hadoop与elasticsearch踩坑笔记

2023-09-12 14:00——2023.09.13 20:06 目录 00、软件版本 01、阿里云服务器部署hadoop 1.1、修改四个配置文件 1.1.1、core-site.xml 1.1.2、hdfs-site.xml 1.1.3、mapred-site.xml 1.1.4、yarn-site.xml 1.2、修改系统/etc/hosts文件与系统变量 1.2.1、修改主机名解…

JWT靶场通关(3关)

启动环境 将文件拷贝到kali虚拟机的桌面&#xff0c;在终端中进入桌面&#xff0c;输入下面命令&#xff0c;安装靶场&#xff0c;端口指定为8888&#xff1a; sudo java -jar webgoat-server-8.0.0.M17.jar --server.port8888如图&#xff0c;启动成功&#xff1a; 打开bp…

docker系列-报错以及解决指南

1. windows运行docker报错Windows Hypervisor is not presentDocker Desktop is unable to detect a Hypervisor.Hardware assisted virtualization and data execution protection must be enabled in the BIOS. Docker Desktop - Windows Hypervisor is not presentDocker D…

论文阅读之Learning and Generalization of Motor Skills by Learning from Demonstration

0、论文基本信息 DMP经典论文 论文题目&#xff1a;Learning and Generalization of Motor Skills by Learning from Demonstration 会议名称&#xff1a;2009 ICRA 论文作者&#xff1a;Peter Pastor, Heiko Hoffmann, Tamin Asfour and Stefan Schaal 作者简介&#xff1a;…

Excel 公式函数:学习基本示例

数据准备 对于本教程&#xff0c;我们将使用以下数据集。 家居用品预算 S / N项目数量价格小计价格适中吗&#xff1f;1芒果96002橘子312003番茄125004食用油565005汤力水133900 房屋建筑项目时间表 S/NITEM开始日期结束日期持续时间&#xff08;天&#xff09;1调查土地0…