JS 文件上传之 FileReader

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/for_cxc/article/details/64129007
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>SA</title>
    <link rel="stylesheet" href="http://oscxc.oschina.io/open/open.css">
    <script src="http://oscxc.oschina.io/open/open.js"></script>
    <script>
        $.domLoad(function () {
            $("#bt").onclick = function () {
                var file = document.createElement("input");
                file.setAttribute("type","file");
                file.setAttribute("multiple",true);
                file.click();
                file.onchange = function () {
                    var reader = new FileReader();
                    reader.onload = function () {
                        var data = this.result;
                        var length = data.length;
                    };
                    reader.readAsArrayBuffer(this.files[0]);
                };
            };
//            $.get("/home/SayHi",function (data) {
//                console.log(data);
//            });
        });
    </script>
</head>
<body>
<input type="button" id="bt" value="上传文件">
</body>
</html>

猜你喜欢

转载自blog.csdn.net/for_cxc/article/details/64129007
今日推荐