javascript - react input file
問題描述
1 在我的頁面中有一個隱藏的input type 類型的file元素,該元素通過ref屬性可以獲取到,取名為this.inputFile 2 頁面頭部右邊有一個按鈕,點(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. 前端 - html5 audio不能播放2. java固定鍵值轉(zhuǎn)換,使用枚舉實(shí)現(xiàn)字典?3. vim - win10無法打開markdown編輯器4. mysql - 千萬數(shù)據(jù) 分頁,當(dāng)偏移量 原來越大時,怎么優(yōu)化速度5. 如何解決tp6在zend中無代碼提示6. javascript - 有沒有類似高鐵管家的時間選擇插件7. 這是什么情況???8. python - flask學(xué)習(xí),user_syy添加報(bào)role is invalid keyword for User.9. css - BEM 中塊(Block)有木有什么標(biāo)準(zhǔn) 何時決定一個部分提取為塊而不是其父級的元素呢(Element)?~10. javascript - 微信網(wǎng)頁開發(fā)從菜單進(jìn)入頁面后,按返回鍵沒有關(guān)閉瀏覽器而是刷新當(dāng)前頁面,求解決?
