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

Posted jinsuo

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了点击上传修改图片(未上传服务器)相关的知识,希望对你有一定的参考价值。

<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>

 

以上是关于点击上传修改图片(未上传服务器)的主要内容,如果未能解决你的问题,请参考以下文章