相关疑难解决方法(0)

如何允许input type = file在react组件中选择相同的文件

我有一个react组件,它呈现一个<input type="file">dom,允许用户从浏览器中选择图像.我发现当我选择相同的文件时,它的onChange方法没有被调用.经过一些搜索,有人建议使用this.value=nullreturn 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中工作.

javascript reactjs

26
推荐指数
6
解决办法
4万
查看次数

标签 统计

javascript ×1

reactjs ×1