<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<style type="text/css">
*{margin: 1%}
</style>
<title>Document</title>
<style>
.div_imgall {border:1px solid #cccccc;width:120px;height:120px;position:relative;}
.input_flie {display:block;width:100%;height:100%;opacity:0;z-index:100;position:absolute;left:0;top:0;}
.div_shuline {position:absolute;width:50%;height:2%;background-color:#cccccc;left:25%;top:49%;z-index:-1;}
.div_hengline {position:absolute;width:2%;height:50%;background-color:#cccccc;left:49%;top:25%;z-index:-1;}
</style>
</head>
<body>
<form method="post" action="./upimage.php" enctype="multipart/form-data">
上传文件到数据库:
<div class="div_imgall">
<input type="file" class="input_flie" name="form_data" id="chooseImg"/>
<div class="jiahao">
<div class="div_shuline"></div>
<div class="div_hengline"></div>
</div>
<img src="" alt="" id="preview" style="width: 100px;height: 100px;padding:8px;z-index: 6;" />
</div>
<input type="submit" name="submit" value="提交">
<img src="" id="preview" style="width: 150px;height: 150px;margin-top: 100px;margin-left: 100px;">
</form>
<script>
var inp=document.getElementById("chooseImg")
inp.onchange=function(){
var file=this.files[0]
console.log(file)
imageUrl = URL.createObjectURL(file);
image = document.getElementById("preview");
image.src = imageUrl;
}
</script>
</body>
</html>
代码中有两个img,想要将input上传的图片显示在两处,但是只有上传的方框中那个img有图片,外面的img没有图片,怎么让外面的这个img也获取到上传的图片?