【发布时间】:2017-01-21 22:22:52
【问题描述】:
我有一个反应组件,它呈现一个<input type="file"> dom 以允许用户从浏览器中选择图像。我发现当我选择同一个文件时,它的 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 中工作。
【问题讨论】:
-
这只是与反应无关的浏览器行为,文件没有改变。见stackoverflow.com/questions/4109276/…
标签: javascript reactjs