我有一个反应组件,它呈现一个 <input type="file">
域,允许用户从浏览器选择图像。我发现当我选择相同的文件时,它的 onChange 方法没有被调用。在一些搜索之后,有人建议在 onChange 方法的末尾使用 this.value=null
或 return false
,但是我已经试过了,但是没有用。
下面是我的代码:
<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 中工作。