簡體   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