javascript - react input file
問題描述
1 在我的頁面中有一個(gè)隱藏的input type 類型的file元素,該元素通過ref屬性可以獲取到,取名為this.inputFile 2 頁面頭部右邊有一個(gè)按鈕,點(diǎn)擊該按鈕,觸發(fā)該this,fileInput.click()3 但是結(jié)果卻無法彈出文件選擇框,真是的,這是什么問題啊,邏輯沒問題啊 尷尬
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(’點(diǎn)擊上傳’); if(this.fileInput){console.log(’進(jìn)入判斷’);//很神奇,必須有這行代碼,才能調(diào)用圖片選擇,我也很無奈啊。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:貼具體代碼啊,這樣好難腦補(bǔ)
相關(guān)文章:
1. css3 - 微信前端頁面遇到的transition過渡動(dòng)畫的bug2. javascript - 請(qǐng)教如何獲取百度貼吧新增的兩個(gè)加密參數(shù)3. 網(wǎng)頁爬蟲 - Python 爬蟲中如何處理驗(yàn)證碼?4. mysql - 分庫分表、分區(qū)、讀寫分離 這些都是用在什么場景下 ,會(huì)帶來哪些效率或者其他方面的好處5. Python爬蟲如何爬取span和span中間的內(nèi)容并分別存入字典里?6. css - input間的間距和文字上下居中7. mysql 一個(gè)sql 返回多個(gè)總數(shù)8. python - 能通過CAN控制一部普通的家用轎車嗎?9. (python)關(guān)于如何做到按win+R再輸入文件文件名就可以運(yùn)行?10. Python如何播放還存在StringIO中的MP3?
