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. mysql - 一个sql的问题2. 百度地图api - Android 百度地图 集成了定位,导航 相互的jar包有冲突?3. 在windows下安装docker Toolbox 启动Docker Quickstart Terminal 失败!4. node.js - nodejs debug问题5. 如何解决Centos下Docker服务启动无响应,且输入docker命令无响应?6. node.js - express框架,设置浏览器从缓存中读取静态文件,只有js从缓存中读取了,css还有一些图片为何没有从缓存中读取?7. spring-mvc - spring-session-redis HttpSessionListener失效8. python - flask post提交timestamp不能作为参数,这是为什么?9. android glide asbitmap 在baseadpter中的问题10. 前端 - @media query 使用出现的问题?

网公网安备