繁体   English   中英

如何使用react.js中的引用从类型文件的html输入形式获取文件数据

[英]How to get the file data from an html input form of type file, using refs in react.js

<input type="file" ref="file" size="45" />

我想从MSDN fileInputElement.files[0]类似的信息,但是我这样做了ReactDOM.findDOMNode(this.refs.file).files[0]但是没有返回任何数据。

this.refs.file.files[0]

对我来说很好

<input type="file" name="sendAttachment" 
       ref={(input) => {  this.sendFile  = input; }}
       onChange={  (e)=>{this.sendAttachment(e)  }} />

sendAttachment(e) 
{
  e.preventDefault();
  console.log(this.sendFile.files[0]);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM