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. 在應用配置文件 app.php 中找不到’route_check_cache’配置項2. html按鍵開關如何提交我想需要的值到數據庫3. HTML 5輸入框只能輸入漢字、字母、數字、標點符號?正則如何寫?4. gvim - 誰有vim里CSS的Indent文件, 能縮進@media里面的5. 跟著課件一模一樣的操作使用tp6,出現了錯誤6. PHP類屬性聲明?7. objective-c - ios 怎么實現微信聯系列表 最好是swift8. javascript - 請教如何獲取百度貼吧新增的兩個加密參數9. html - 微信瀏覽器h5<video>標簽問題10. java - 安卓接入微信登錄,onCreate不會執行
