我有一个react组件,它呈现一个<input type="file">dom,允许用户从浏览器中选择图像.我发现当我选择相同的文件时,它的onChange方法没有被调用.经过一些搜索,有人建议使用this.value=null或return false在onChange方法的最后,但我尝试它不起作用.
以下是我的代码:
<input id="upload" ref="upload" type="file" accept="image/*"
onChange={(event)=> { this.readFile(event) }}/>
Run Code Online (Sandbox Code Playgroud)
以下是我的尝试:
<input id="upload" ref="upload" type="file" accept="image/*"
onChange={(event)=> {
this.readFile(event)
return false
}}/>
Run Code Online (Sandbox Code Playgroud)
另一个是:
<input id="upload" ref="upload" type="file" accept="image/*"
onChange={(event)=> {
this.readFile(event)
this.value=null
}}/>
Run Code Online (Sandbox Code Playgroud)
我相信上面的解决方案适用于jquery,但我不知道如何让它在reactjs中工作.