首页 > 技术文章 > JQuery------获取<input type="file">中的文件内容

tianhengblogs 2016-10-19 15:33 原文

html

<div class="File">添加附件</div><input id="upfile" name="upfile" type="file" multiple="multiple" style="display:none" />
<div class="FileArea"></div>

 

js

var str = "";
    $("#upfile").click();
    $("#upfile").on("change", function () {
        var obj = document.getElementById("upfile");
        var length = obj.files.length;
        for (var i = 0; i < length; i++) {
            $(".FileArea").html("");;
            var temp = obj.files[i].name;
            str += "<div>" + temp + "</div>";
        }
        $(".FileArea").append(str);
    });

 

推荐阅读