แสดงตัวอย่างภาพก่อนอัพโหลด

แสดงตัวอย่างภาพก่อนอัพโหลด





HTML

 <body>

               <input type="file" accept="image/*" onchange="loadFile(event)">      

               <p><img id="output" width="150"/></p>     

 </body>{codeBox}


javascript

<script>

                const loadFile = function(event) {

                        const image = document.getElementById('output');

                       image.src=URL.createObjectURL(event.target.files[0]);

               }; 

</script>{codeBox}


Example


<!DOCTYPE html>

<html>  

        <head>     

             <title>imgae upload and display</title>   

        </head>   

        <body>       

               <input type="file" accept="image/*" onchange="loadFile(event)">      

               <p><img id="output" width="150"/></p>       

        <script>

                const loadFile = function(event) {

                       const image = document.getElementById('output');

                       image.src=URL.createObjectURL(event.target.files[0]);

               }; 

        </script>

        </body>

</html> 

{codeBox}



ที่มาครูสมชายคัดมาจาก : {getButton} $text={อ้างอิงที่มา} $icon={link} $color={red} 
>>>TRY TO CHECK OUT , IF ANY ERROR FOUND. PLEASE LET ME KNOW BY COMMENT.
I'LL TRY MY LEVEL BEST TO FIX THE PROBLEM.
                                                                THANKS FOR VISITING thumariya.blogspot
Have a nice day!
-------------------------- -------------------------
>>>ลองตรวจสอบหากพบข้อผิดพลาด โปรดแจ้งให้เราทราบโดยแสดงความคิดเห็น
ฉันจะพยายามระดับของฉันให้ดีที่สุดเพื่อแก้ไขปัญหา
ขอบคุณสำหรับการเยี่ยมชม thumariya.blogspot
ขอให้เป็นวันที่ดี!

-------------------------- -------------------------

{fullWidth}


แสดงความคิดเห็น (0)
ใหม่กว่า เก่ากว่า