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. Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?2. android - webview 自定义加载进度条3. 如何解决Centos下Docker服务启动无响应,且输入docker命令无响应?4. angular.js - Web应用,单页面应用Cache问题5. css3 - 这个效果用 CSS 可以实现吗?border-image6. position:absolute、float、display:inline-block 都能实现相同效果,区别是什么?7. javascript - vue更改当前节点元素8. javascript - echart2.0 饼图不能自适应???9. angular.js - angular post的Content-Type被设置,导致不能上传图片,求助!!10. vue.js - vue 打包后 nginx 服务端API请求跨域问题无法解决。

网公网安备