javascript - react input file
問題描述
1 在我的頁面中有一個隱藏的input type 類型的file元素,該元素通過ref屬性可以獲取到,取名為this.inputFile 2 頁面頭部右邊有一個按鈕,點擊該按鈕,觸發(fā)該this,fileInput.click()3 但是結果卻無法彈出文件選擇框,真是的,這是什么問題啊,邏輯沒問題啊 尷尬
class FileManage extends Component{
constructor(props){ super(props); this.onHandleBack = this.onHandleBack.bind(this); this.showOperationSheet = this.showOperationSheet.bind(this);} onHandleBack(){ this.props.history.goBack();}showOperationSheet(){ console.log(’點擊上傳’); if(this.fileInput){console.log(’進入判斷’);//很神奇,必須有這行代碼,才能調用圖片選擇,我也很無奈啊。console.log(this.fileInput.click());this.fileInput.click() }};render(){ return (<p> <p onClick={this.showOperationSheet}>按鈕</p> <p style={{display:'none'}}><form action='' encType='multipart/form-data' method=’POST’ onSubmit={this._onSubmit}> <input type='file' ref={(input)=>{this.fileInput = input}} onChange={this._onChange}/></form></p></p> )}
}export default FileManage
問題解答
回答1:貼具體代碼啊,這樣好難腦補
相關文章:
1. Docker for Mac 創(chuàng)建的dnsmasq容器連不上/不工作的問題2. java - instance method中 static后的<K>是什么意思?3. javascript - QWebEngineView 如何爬 angular 的動態(tài)數據?4. java - com.android.internal.R.attr.dialogTheme 這個dialogTheme的內容再哪里查看?5. java - 一段遞歸代碼的問題6. python3.x - python連oanda的模擬交易api獲取json問題第五問7. css3 - 圖片等比例縮放8. java - 關于File的問題?9. html5 - 這個代碼顯示功能如何實現?10. 錯誤:java.lang.NoSuchMethodError:org.objectweb.asm.ClassWriter。<init>(I)V
