js實現圖片選中馬上顯示圖片名,選擇后可以預覽,即選即顯


<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>    
        <input type="file" onchange="show(this)"/>
        <img id="img" src="">
        <script>        
            function show(file){    
                var reader = new FileReader();    // 實例化一個FileReader對象,用於讀取文件
                var img = document.getElementById('img');     // 獲取要顯示圖片的標簽
                
                //讀取File對象的數據
                reader.onload = function(evt){
                    img.width  =  "80";
                    img.height =  "80";
                    img.src = evt.target.result;
                }
                reader.readAsDataURL(file.files[0]);
            }    
        </script>    
    </body>

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM