上傳圖片預覽
圖片上傳前先預覽,沒想到比我以為的簡單,這裡圖方便用 jQuery 來寫。
重點在於用 URL.createObjectURL 建立圖片的 src 網址。
重點在於用 URL.createObjectURL 建立圖片的 src 網址。
<input type="file" name="image" accept="image/*">
<img class="current-image" src="#">
<script type="text/javascript">
$(function () {
$("input[name=image]").change(function (e) {
$(".current-image").attr("src", URL.createObjectURL(e.target.files[0]));
});
});
</script>
留言
張貼留言