js简单上传图片预览功能-简单粗暴
js简单上传图片预览功能
<!doctype html><html><head><title>js简单上传图片预览功能</title><meta http-equiv="content-type" content="text/html; charset=utf-8"><script src="http://www.codefans.net/ajaxjs/jquery-1.6.2.min.js"></script></head><body><h3>请选择图片文件:jpg/gif</h3><form name="form0" id="form0" >    <input type="file" name="file0" id="file0" multiple="multiple" />    <br>    <img src="" id="img0" width="150" height="150" style="display:none;"></form></body></html> <script type="text/javascript">$("#file0").change(function(){    var objurl = getobjecturl(this.files[0]) ;    console.log("objurl = "+objurl) ;    if (objurl) {        $("#img0").attr("src", objurl) ;        $("#img0").show();    }}) ;//建立一個可存取到該file的urlfunction 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>
推荐教程:《js基础教程》
以上就是js简单上传图片预览功能的实例详解的详细内容。
   
 
   