<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>人脸识别系统</title>
<script src="jquery/jquery-3.3.1.min.js"></script>
</head>
<body>
<input id="input-file" class="upload" type="file" value="">
<br>
<img src="" alt="">
</body>
<script>
$(function(){
$('.upload').change(function(){
var oFReader = new FileReader();
console.log(oFReader);
var file = document.getElementById('input-file').files[0];
console.log(file);
oFReader.readAsDataURL(file);
oFReader.onloadend = function(oFRevent){
var src = oFRevent.target.result;
$('img').prop('src',src);
}
})
})
</script>
</html>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>人脸识别系统</title>
<script src="jquery/jquery-3.3.1.min.js"></script>
</head>
<body>
<input id="input-file" class="upload" type="file" value="">
<div id = "imgContainer">
</div>
</body>
<script>
$(document).on('change', '#input-file', function () {
console.log(this.files[0]);
function getObjectURL(file) {
var url = null;
if (window.createObjcectURL != undefined) {
url = window.createOjcectURL(file);
console.log(url);
} else if (window.URL != undefined) {
url = window.URL.createObjectURL(file);
console.log(url);
} else if (window.webkitURL != undefined) {
url = window.webkitURL.createObjectURL(file);
console.log(url);
}
return url;
}
var objURL = getObjectURL(this.files[0]);
alert(objURL);
$('#imgContainer').html("<img src='" + objURL + "' alt='Alternate Text' width='640px' height='350px' id='target' />");
cutImg();
});
</script>
</html>
隐藏 文件 选择夹 直接显示图片
<body>
<div id="regcoDiv">
</div>
</body>
function chooseFile() {
$("#file1").trigger('click');
}
function imageTo()
{
$("#regcoDiv").empty();
let imageInput = "<h2>点击图片区域上传文件</h2><input style='display: none' type='file' name='file1' id='file1' multiple='multiple' /><br><img src='images/shibie.jpg' οnclick='chooseFile()' id='img0' style='width: 30rem;height: 25rem;'>";
$("#regcoDiv").append(imageInput);
}