<input type="file" id="picFile" />
function readFile() { var obj = document.getElementById("picFile"); if (obj.files.length < 1) { console.log("请选择文件"); return; } var file = obj.files[0]; if (!/image\/\w+/.test(file.type)) { console.log("请确保文件为图像类型"); return; } var reader = new FileReader(); reader.readAsDataURL(file); reader.onload = function (e) { //console.log(e.target.result); console.log(this.result); } }