<!DOCTYPE html>
<html>
<head>
<title>图片上传预览</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="https://www.linuxidc.com/files/2017/11/jquery-1.6.2.min.js"></script>
</head>
<body>
<form >
<input type="file" multiple="multiple" />
<br>
<img src="" >
</form>
<script>
$("#file0").change(function(){
var objUrl = getObjectURL(this.files[0]) ;
console.log("objUrl = "+objUrl) ;
if (objUrl) {
$("#img0").attr("src", objUrl) ;
}
}) ;
//取得该文件的url
function getObjectURL(file) {
var url = null ;
if (window.createObjectURL!=undefined) {
url = window.createObjectURL(file) ;
} else if (window.URL!=undefined) {
url = window.URL.createObjectURL(file) ;
} else if (window.webkitURL!=undefined) {
url = window.webkitURL.createObjectURL(file) ;
}
return url ;
}
</script>
</body>
</html>
JavaScript 中的FileReader对象实现上传图片本地预览(2)
内容版权声明:除非注明,否则皆为本站原创文章。
转载注明出处:https://www.heiqu.com/6d1be177e0cf59613a006e6c49231644.html