javascript - 反应输入文件
我想大声告诉你
我想大声告诉你 2017-07-05 10:44:09
0
1
914

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)
学霸

贴具体代码啊,这样好难脑补

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!