如何显示输入时选择的图像?
How to display image selected on input?
我正在尝试显示所选图像,但我不断收到以下错误:
Not allowed to load local resource:
知道为什么吗?
<input type='file' id='fileName' name='fileName' capture='user' accept='image/*' onchange=\"document.getElementById('myImg').src = window.URL.createObjectURL(this.files[0])\">
<p><img src='#' id='myImg'></p>
你的 onchange 事件有错误,我尝试了代码并且有效
onchange="document.getElementById('myImg').src = window.URL.createObjectURL(this.files[0])"
同意@tantoui zakaria。您似乎试图用 前斜杠 (/) 转义双引号 他的代码按预期工作!
我正在尝试显示所选图像,但我不断收到以下错误:
Not allowed to load local resource:
知道为什么吗?
<input type='file' id='fileName' name='fileName' capture='user' accept='image/*' onchange=\"document.getElementById('myImg').src = window.URL.createObjectURL(this.files[0])\">
<p><img src='#' id='myImg'></p>
你的 onchange 事件有错误,我尝试了代码并且有效
onchange="document.getElementById('myImg').src = window.URL.createObjectURL(this.files[0])"
同意@tantoui zakaria。您似乎试图用 前斜杠 (/) 转义双引号 他的代码按预期工作!