用html5和jquery写的一个文件上传的Demo
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="js/jquery-3.3.1.js"></script>
</head>
<body>
<input id='ipt' style='display: none;' type="file" multiple>
<button id='btn'>上传</button>
<script>
btn.onclick = function(){
ipt.click();
}
ipt.onchange = function(){
for (var i = 0; i < ipt.files.length; i++) {
var fr = new FileReader();
var file = ipt.files[i];
console.log(file);
fr.readAsDataURL(file);
fr.onload = function(){
var img = document.createElement('img');
img.src=this.result;
img.width=300;
document.body.appendChild(img);
document.body.innerHTML += file.name+' '+ file.lastModifiedDate+' '+ (file.size/1024).toFixed(1)+'kb '+file.type;
}
}
}
</script>
</body>
</html>
一个小小的案例就完成啦,每天写一点总会成为有进步,至少比昨天更好