点击上传修改图片(未上传服务器)

<body>
 <input type="file" name="file" id="file" onClick="$('#file').click();" style="display:block" 
       onChange="var img=getObjectURL(this.files[0]);$('#myimg').attr('src',img)" />
<img id="myimg" src="" style="pointer-events: none;"/>

</body>
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<script type="text/javascript">

    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>

 

posted @ 2016-11-08 23:50  Jinsuo  阅读(653)  评论(0编辑  收藏  举报