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. docker images顯示的鏡像過多,狗眼被亮瞎了,怎么辦?2. docker start -a dockername 老是卡住,什么情況?3. 前端 - nginx里面怎么配置支持127.0.0.1:82下 html文件支持include4. 請教各位大佬,瀏覽器點 提交實例為什么沒有反應5. phpstudy啟動不了服務里面的進程,怎么辦?6. angular.js - angurlarJS的安卓的微信端中用加載ngCookies會出錯的問題7. java - 微信開發遇到一個 bug。。access_token 有關的8. angular.js - 怎樣在使用ng-repeat屬性的標簽里面監聽單個事件,使其能夠單個改變CSS。9. node.js - 微信的自動回復問題10. 找一個權威、實戰的微信掃碼授權登錄網站的開發教程或者文章
