<div class=”upload_box”>
<div id=”preview”>
<img id=”imghead” src=”0.jpg” width=”190″ height=”130″/> <!–圖片顯示位置–>
</div>
<b>上傳圖片</b>
<input type=”file” name=”file” id=”file” accept=”image/*” onchange=”imgChange(this);”/> <!–檔案上傳選擇按鈕–>
</div>
<script type=”text/javascript”>
// 選擇圖片顯示
function imgChange(obj) {
//獲取點選的文字框
var file =document.getElementById(“file”);
var imgUrl =window.URL.createObjectURL(file.files[0]);
var img =document.getElementById(`imghead`);
img.setAttribute(`src`,imgUrl); // 修改img標籤src屬性值
};
</script>