javascript - react input file
問題描述
1 在我的頁面中有一個隱藏的input type 類型的file元素,該元素通過ref屬性可以獲取到,取名為this.inputFile 2 頁面頭部右邊有一個按鈕,點擊該按鈕,觸發該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. javascript - ionic1的插件如何遷移到ionic2的項目中2. java - 如何在Fragment中調用Activity的onNewIntent?3. javascript - h5上的手機號默認沒有識別4. mysql里的大表用mycat做水平拆分,是不是要先手動分好,再配置mycat5. css - 關于input標簽disabled問題6. python - 獲取到的數據生成新的mysql表7. 怎么用css截取字符?8. window下mysql中文亂碼怎么解決??9. javascript - jquery hide()方法無效10. python的文件讀寫問題?
