JS 檔案上傳之 FileReader
阿新 • • 發佈:2018-12-24
<!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>