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

客語檢定

客語檢定

恭喜通過客語基礎檢定,期待你將來可以直接用客語跟我對話。

CentOS 5.2 使用 YUM 將 PHP 5.1.6 更新到 5.2.6

CentOS 5.2 使用 ...

CentOS 5. 版內建的 PHP 版本為 5..,甚至於 5. 版仍舊是 5.. 版本。 基於系...

IE10 在 fckeditor無正常顯示及無法輸入任何字元

IE10 在 fckedit...

於fckorcodeie.js 檔案中, 在B.open(‘GET’, A, false); 及 B...

Recommended reading

Other stories happened at this address

紅蘿蔔山藥木耳牛肉湯~

紅蘿蔔山藥木耳牛肉湯~

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

生日快樂

生日快樂

月日,是父親大人的生日。 在這裡放上一張老照片,祝福您生日快樂!! 年輕的時候真的還是挺帥的,也難怪...

稍稍紀錄一下中秋節的天

稍稍紀錄一下中秋節的天

好幾天沒紀錄故事了,原因是因為趕著客戶的專案。 今年下半年很熱鬧啊,看來似乎就要沒有喘口氣的機會了。...

嘗試用CSS畫圖

嘗試用CSS畫圖

一直想為innstory設計的房子圖案,為了讓瀏覽速加快,最後還是決定用CSS 完成 a 用CSS畫...

小孩很忙~

小孩很忙~

a a a a a a a 小孩很忙~ 照顧小小孩雖然辛苦, 但等到他回台北後, 不免,還是會失落的...

藝術無所不在

藝術無所不在

當U了解到繪畫所帶來的樂趣~ 自當所到之處無一倖免。 最新作品,彩繪考卷,用色大膽有深度,黃色跟紅色...

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