input 操作

xiaoxiao2021-02-28  67

H5 调用,camera照相机;camcorder摄像机;microphone录音。accept表示,直接打开系统文件目录。

<input type="file" id='image' accept="image/*" capture='camera'>

其实html5的input:file标签还支持一个multiple属性,表示可以支持多选

<input type="file" id="file" multiple>

在各个机型都可以点击 file 调用相册 和 摄像头拍照 1. 在老版本的安卓中,必须加上capture,否则只能调用相册 2. 在IOS中 加了capture,就只能调用摄像头不能调用相册

解决办法: 判断ios,如果是ios就去掉capture属性.

var file = document.querySelector('input'); if (getIos()) { file.removeAttribute("capture"); } function getIos() { var ua=navigator.userAgent.toLowerCase(); if (ua.match(/iPhone\sOS/i) == "iphone os") { return true; } else { return false; } }

js 操作 file,给ID 加个 click()

fileClick(){ document.getElementById('image').click(); }, <input type="file" id='image' accept="image/*" capture='camera'> <button @click="fileClick">file</button>

转载请注明原文地址: https://www.6miu.com/read-2631006.html

最新回复(0)