手机端上传文件限制类型
<body>
<input type="file" name="" id="f" />
<script>
const qs = v => document.querySelector(v);
const types = [
'video/mp4',
'video/ogg',
'image/jpeg',
'image/jpg',
'image/png',
'image/webp',
];
const fEl = qs('#f');
fEl.addEventListener('change', e => {
const files = fEl.files;
if (!files.length) return;
const file = files[0];
const fType = file.type;
if (types.some(typeStr => typeStr === fType)) {
console.log(file);
} else {
fEl.value = '';
}
});
</script>
</body>