Loading...

讓圖片上傳前先產生預覽

Temperature: 0 °C

ChungChung
author_tools

專案需要,上傳圖片至網站時先產生預覽圖~

參考了stackoverflow.com裡討論的的方式Url link

但因為需要同時上傳多個圖,因此改了一下用法,順便紀錄下來~
CSS部份

body { background: #efefef; color: #a3aa8c; } img { max-height: 100px; max-width: 100px; margin: 0 5px; }

Script部份
function readURL(input,kk) {
            if (input.files && input.files[0]) {
                var reader = new FileReader();
 
                reader.onload = function (e) {
                    $('#blah'+kk).attr('src', e.target.result);
                }
 
                reader.readAsDataURL(input.files[0]);
            }
        }

Html部份
<form action="#" method="post" name="Reportform" id="Reportform" enctype="multipart/form-data">
<div><input type="file" name="f[]" onchange="readURL(this,1);" /> <img id="blah1" src="#" alt="show image" /></div>
<div><input type="file" name="f[]" onchange="readURL(this,2);" /> <img id="blah2" src="#" alt="show image" /></div>
<div><input type="file" name="f[]" onchange="readURL(this,3);" /> <img id="blah3" src="#" alt="show image" /></div>
</form>

另外也可使用
URL.createObjectURL() 

的方式

讓圖片上傳前先產生預覽

屏東縣內埔鄉東寧村勝利路 Go

https://innstory.com/story-讓圖片上傳前先產生預覽-707
寫程式筆記

Prev
 檳城美食系列紅豆霜

Next
雞蛋花 

Nearby Attractions

屏東縣內埔鄉東寧村勝利路-Nearby Attractions

  • 新北勢庄東柵門 Go
  • 「清朝下淡水營」遺構 Go
  • 豐田老街 Go
  • 涼山遊憩區 Go
  • 六堆客家文化園區 Go
  • 六堆天后宮 Go

About the Author

Chung

我是chung
網路工作者
主業是網站系統開發建置
副業是做夢,寫故事
作品請參考/teme.biz
做夢請參考/innstory.com
聯絡/chung.teme@gmail.com

#有人用筆寫日記,有人用歲月寫日記,有人用照片寫日記,而我,用innstory寫日記。

Visitor message

Leave some footprints to prove that you visited me

Recommended reading

Author's other related stories

CSS透明度

CSS透明度

CSS 透明度的實作, 各種瀏覽器和標準如下:(數字越小越透明) 標準: opacity:~ (Fi...

新舊交替,使用phpmyadm出現1064 error in CREATE TABLE … TYPEMYISAM錯誤

新舊交替,使用phpmyad...

sql55 系統移機的過程中,最重要的環節....我想...莫過於是系統的環境了....。 這次在協...

DIV區塊內文字左右對齊?

DIV區塊內文字左右對齊?

最近常接到一些英文網站建置的專案....為了讓內容文字能夠左右對齊... 所以我用了以下方式 div...

Recommended reading

Other stories happened at this address

高粱酒真的放越久越好喝嗎?

高粱酒真的放越久越好喝嗎?

這天,父親拿出一瓶建國年的金門高粱。 innimgcWcQRGOB 可惜我的嘴拙,品嘗不出長輩們所說...

2017年除夕

2017年除夕

s 年的今天,U第一次的農曆新年~ 按照慣例,今天必須要到祠堂,跟祖先們報告去年的狀況。 然後請祖先...

2016猴年大年初一

2016猴年大年初一

大年初一,闔家平安.... 過年,就是要大夥聚在一起吃吃喝喝,聊聊去年...想想今年.... 這慣例...

就攪工的鹹魚肉餅

就攪工的鹹魚肉餅

就攪工的鹹魚肉餅

Mandy,母親節快樂~

Mandy,母親節快樂~

第一次當媽~ 完全不用採排,不需要練習.....一切都是那麼的理所當然~ 這小傢伙,我幫他換尿布換了...

紅蘿蔔山藥木耳牛肉湯~

紅蘿蔔山藥木耳牛肉湯~

月子餐若吃太燥熱,難免就會影響到腸胃..... Mandy說她腸胃好像有點不順~........ 這...

Please select an option

error

Hi, thank you for your participation, but you cannot vote repeatedly~

Join innstory now and start recording your story.

"Innstory" is a place to store stories. We are committed to becoming a warm platform. Deepening the bonds between people is our direction.
We are convinced that the blockchain between people is not just a cold calculation. Join us now.

Wrong format