如何在上传图片时,先预览图片,在点击“提交”后存入数据库

解决方案 »

  1.   

    我想用Ajax来实现,但不知道怎样实现
      

  2.   

    http://www.google.com.hk/search?gcx=c&sourceid=chrome&ie=UTF-8&q=%E9%A2%84%E8%A7%88%E5%9B%BE%E7%89%87+js
      

  3.   

    http://www.cnblogs.com/cloudgamer/archive/2009/12/22/ImagePreview.html
      

  4.   

    <input type="file" name="link_pic" class="fl file_input" id="tupian" />
       <input type="button" class="upload_btn fl" value="上传" onclick="yulan2('tupian');"  />
    <tr style="display:none" id="image">
                  <td width="100px">&nbsp;&nbsp;图片预览</td>
                  <td><div id="image2"></div></td>
    JS代码如下:<script>
    function yulan2(str){
    var obj = document.getElementById(str);
    var str = getPath(obj);
    document.getElementById('image').style.display="";
    var liulanqi = getOs();
    if(liulanqi=="Safari")
    {document.getElementById('image2').innerHTML = "该款浏览器无法正常显示待上传的图片,但不会影响图片的正常上传,若要显示待上传的图片,推荐使用IE浏览器登录本系统!";}
    else
    {document.getElementById('image2').innerHTML = "<img src='" + str + "' />";}
    }
    function getOs()   
    {   
        var OsObject = "";   
        if(navigator.userAgent.indexOf("MSIE")>0) {   
             return "MSIE";   
        }   
        if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){   
             return "Firefox";   
        }   
        if(isSafari=navigator.userAgent.indexOf("Safari")>0) {   
             return "Safari";   
        }    
        if(isCamino=navigator.userAgent.indexOf("Camino")>0){   
             return "Camino";   
        }   
        if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){   
             return "Gecko";   
        }   
    } //获取以下即为完整客户端路径
    function getPath(obj) {
    if(obj){
    if(window.navigator.userAgent.indexOf("MSIE") >= 1) {
    obj.select(); return document.selection.createRange().text;
    }else if(window.navigator.userAgent.indexOf("Firefox") >= 1) {
    if (obj.files) {
    return obj.files.item(0).getAsDataURL();
    }
    return obj.value;
    }
    return obj.value;
    }

    </script>
    但是Firefox浏览器可以预览图片,但是IE浏览器却不行,该怎么改呢?
      

  5.   

    感觉不必要吧。预览图片大多用flash来实现。js估计兼容不好弄。上传图片让用户自己截取就好了。jquery有插件。无刷新上传就用iframe实现。