前端那些事之H5本地读取文件

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

h5读取本地文件内容

  • 参考博客地址:http://www.cnblogs.com/leejersey/p/4772504.html

关于input的file框onchange事件触发一次失效的新的解决方法

  • 1:使用代理提交
$(form).on("change","#file",function(e){}

2:用$("#targetFile").replaceWith()方法

  • html

  • js
//文件上传
$("form").on("change", "#updateLicenseFile", function () {
    var files =this.files;
    for (var i = 0, f; f = files[i]; i++) {
        var reader = new FileReader();
        reader.onload = (function (file) {
            return function (e) {
                $("#updateLicense").val(this.result);
            };
        })(f);
        //读取文件内容
        reader.readAsText(f);
    }
    $("#updateLicenseFile").replaceWith('');
});

转载于:https://my.oschina.net/yongxinke/blog/1531062

你可能感兴趣的:(前端那些事之H5本地读取文件)