美文网首页
input 上传文件type="file"

input 上传文件type="file"

作者: Evan_zhan | 来源:发表于2017-08-29 20:30 被阅读0次

    在React中使用input标签上传文件

        <input onChange={ this.onChangeFiles }  type="file"  name="uploadfile" />
    

    当使用onChange事件时,发现两次选择同一文件会不起作用。

    解决方案:
    使用ref获取当前input,每次选择后把valu清空
    <input onChange={ this.onChangeFiles } type="file" ref={ (input) => { this.uploadInput = input; } } name="uploadfile" />

    然后在onChange事件里把value置空

    onChange () {
        将files对象转化为数组
        const files = [].slice.call(e.target.files);   
        ...
        this.uploadInput = "";
    }
    

    Input上传多个文件 multiple属性

    <input type="file" name="" multiple="" />
    

    Input上传文件夹 webkitdirectory属性

    <input type="file" name="" multiple="" webkitdirectory="" />

    相关文章

      网友评论

          本文标题:input 上传文件type="file"

          本文链接:https://www.haomeiwen.com/subject/nssadxtx.html