无法在 IOS 和 Android 移动设备上 select 文件
Unable to select files on Mobile both IOS and Android
我正在尝试能够上传图片以自动更改 table 的背景,但它只能在台式计算机上使用,在任何 IOS 上都不起作用也没有Android,有人有任何指示吗?提前致谢。
const frame = document.getElementById('table');
const file = document.getElementById('file');
const reader = new FileReader();
reader.addEventListener("load", function () {
frame.style.backgroundImage = `url(${ reader.result })`;
}, false);
file.addEventListener('change',function() {
const image = this.files[0];
if(image) reader.readAsDataURL(image);
}, false)
尝试使用对象 url
document.body.id = 'table'
const [{style}, file] = document.querySelectorAll('#table, #file')
file.addEventListener('change', img => {
[img] = file.files
style.backgroundImage = img ? `url(${URL.createObjectURL(img)})` : ''
})
<input type=file id=file accept="image/*">
我正在尝试能够上传图片以自动更改 table 的背景,但它只能在台式计算机上使用,在任何 IOS 上都不起作用也没有Android,有人有任何指示吗?提前致谢。
const frame = document.getElementById('table');
const file = document.getElementById('file');
const reader = new FileReader();
reader.addEventListener("load", function () {
frame.style.backgroundImage = `url(${ reader.result })`;
}, false);
file.addEventListener('change',function() {
const image = this.files[0];
if(image) reader.readAsDataURL(image);
}, false)
尝试使用对象 url
document.body.id = 'table'
const [{style}, file] = document.querySelectorAll('#table, #file')
file.addEventListener('change', img => {
[img] = file.files
style.backgroundImage = img ? `url(${URL.createObjectURL(img)})` : ''
})
<input type=file id=file accept="image/*">