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. python - 关于beautifulsoup获取文档内容2. dockerfile - 为什么docker容器启动不了?3. debian - docker依赖的aufs-tools源码哪里可以找到啊?4. android - java tm platform se binary 占用很多内存5. mysql里的大表用mycat做水平拆分,是不是要先手动分好,再配置mycat6. mysql - 如何在数据库里优化 汉明距离 查询?7. node.js - ionic2 创建项目 ionic server 报这个错 有朋友可以帮忙看看吗!8. python flask做的文件系统上传系统,路径没错,文件列表加载不出来,error 100539. node.js - nodejs连接mysql,输入指令为什么10. python - 《flask web 开发》一书,数据库中多对多关系的实现问题?
