如何允许输入类型=文件在反应组件中选择相同的文件 [英] How to allow input type=file to select the same file in react component
问题描述
我有一个反应组件,它呈现一个 <input type="file">
dom 以允许用户从浏览器中选择图像.我发现当我选择同一个文件时,它的 onChange 方法没有被调用.经过一番搜索,有人建议在 onChange 方法的末尾使用 this.value=null
或 return false
但我尝试过它不起作用.
I have a react component which renders a <input type="file">
dom to allow user select images from browser. I found that its onChange method not called when I select the same file. After some searching, someone suggests using this.value=null
or return false
at the end of the onChange method but I have tried it doesn't work.
下面是我的代码:
<input id="upload" ref="upload" type="file" accept="image/*"
onChange={(event)=> { this.readFile(event) }}/>
以下是我尝试过的:
<input id="upload" ref="upload" type="file" accept="image/*"
onChange={(event)=> {
this.readFile(event)
return false
}}/>
另一个是:
<input id="upload" ref="upload" type="file" accept="image/*"
onChange={(event)=> {
this.readFile(event)
this.value=null
}}/>
我相信上述解决方案适用于 jquery,但我不知道如何让它在 reactjs 中工作.
I believe above solutions work for jquery but I don't know how to let it work in reactjs.
推荐答案
这篇关于如何允许输入类型=文件在反应组件中选择相同的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!