在html中使用javascript显示本地图片的

<html>
    <head>
        <script type="text/javascript">
            function getFullPath(obj){ 
                if(obj){ 
                    //ie 
                    if (window.navigator.userAgent.indexOf("MSIE")>=1) { 
                        obj.select();
                        return document.selection.createRange().text; 
                    } 
                    //firefox 
                    else if(window.navigator.userAgent.indexOf("Firefox")>=1){ 
                        if(obj.files){
                            return window.URL.createObjectURL(obj.files.item(0)); 
                        }
                        return obj.value; 
                    }
                    return obj.value;
                }
            }
        </script>
    </head>
    <body>
        <input type="file" onchange="document.getElementById('img').src=getFullPath(this);" />
        <img id="img" />
    </body>
</html>

 

posted @ 2014-04-16 11:44  taxuexunmei77  Views(522)  Comments(0Edit  收藏  举报