我有一个“按钮”(一个像按钮一样的锚点)。您可以在哪里上传获取预览的图片。显示上传的图片而不是上传按钮
但我想要做的是让上传的图片显示,而不是按钮(相同的大小等)。有没有这样做的好方法?
$(document).ready(function() {
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (event) {
$('#imageChosen').attr('src', event.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$('#fileInput').change(function(){
readURL(this);
});
});
div.input {
border-style: solid;
border-width: 5px;
\t display: inline-block;
}
#filebutton {
\t width: 100px;
\t height: 100px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
<head>
\t <title>for testing</title>
\t <script src="js/jquery-3.2.1.min.js"></script>
\t <script src="js/costum.js"></script>
\t <link rel="stylesheet" type="text/css" href="css/costum.css">
</head>
<body>
\t <div class="input">
\t \t <label for="fileInput">
\t \t \t <input type="file" id="fileInput" style="display: none;" />
\t \t \t <a style="display: block;" type="button" id="filebutton">Upload</a>
\t \t \t <img id="imageChosen">
\t \t </label> \t
\t </div>
</body>
</html>
我会在与此picure底部一些空白。 – vonhact
我编辑了我的答案。 –