首页 > 编程语言 > 详细

javascript预览本地图片

时间:2016-03-10 10:44:16      阅读:139      评论:0      收藏:0      [点我收藏+]
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="buexplain">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
<script src="jquery.js"></script>
</head>
<body>
    <input type="file" id="imgfile">
    <img id="imgsrc" src="">
    <script>
        $(function() {
            $("#imgsrc").hide();
            $("#imgfile").change(function() {
                var objUrl = getObjectURL(this.files[0]);
                console.log("objUrl = " + objUrl);
                if (objUrl) {
                    $("#imgsrc").attr("src", objUrl);
                    $("#imgsrc").show();
                }
            });

            function getObjectURL(file) {
                var url = null;
                if (window.createObjectURL != undefined) { // basic
                    url = window.createObjectURL(file);
                } else if (window.URL != undefined) { // mozilla(firefox)
                    url = window.URL.createObjectURL(file);
                } else if (window.webkitURL != undefined) { // webkit or chrome
                    url = window.webkitURL.createObjectURL(file);
                }
                return url;
            }
        });
    </script>
</body>
</html>

 

javascript预览本地图片

原文:http://www.cnblogs.com/buexplain/p/5260804.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!