
HTML部分
<div class="upload"> <div class="upload-icon"> <input type="file" id="inputFile" accept="image/gif, image/jpeg" style="display: none;" οnchange="changeAgentContent()"> <input type="text" value="" disabled style="display: none;" id="inputFileAgent" /> <input type="button" class="upload-input" id="upload" value="Browse..." /> <img src="../imgs/camera.png" alt="" class="img"> </div> <div class="upload-title">上传照片</div></div>
CSS部分
.upload { position: relative; margin-top: 4.67vw; display: flex; flex-direction: row; justify-content: flex-start; align-items: center; .upload-icon { width: 13.33vw; height: 13.33vw; background-color: #ffffff; box-shadow: 0vw 0.4vw 1.33vw 0vw rgba(0, 0, 0, 0.1); border-radius: 0.53vw; overflow: hidden; line-height: 0; border: solid 0.27vw #e2e2e2; box-sizing: border-box; padding: 4vw 3.6vw; margin-right: 4vw; .upload-input { position: absolute; display: block; width: 13.33vw; height: 13.33vw; background-color: transparent; top: 0; left: 0; z-index: 1; outline: none; border: none; } } .upload-title { font-size: 3.73vw; color: #999999; }}
JS部分
document.getElementById('upload').onclick = function() { document.getElementById('inputFile').click()}function changeAgentContent(){ document.getElementById("inputFileAgent").value = document.getElementById("inputFile").value;}