2013-10-27 172 views
0

我希望能夠在形式預覽圖片,上載,我已經定製<input type="file">
enter image description here
我需要加內用圖像來代替矩形前預覽圖像上傳了多張圖片

我該怎麼做?
這是我的HTML和CSS http://jsfiddle.net/YJG79/2/

+0

您需要通過AJAX或通過某種iframe實現上傳圖像。 [Uploadify](http://www.uploadify.com/)是一款非常棒的遊戲,我建議您嘗試一下。它使用jQuery和1x1閃存像素來允許上傳,而無需實際提交表單。 – Lix

+1

許多插件,你可以用來做到這一點...做一些網絡搜索上傳插件 – charlietfl

+0

@Lix我檢查了Uploadify,但它不顯示圖像,只是進度條:( – Heidel

回答

0

是的,你可以在上傳表單

試試這個Example

由於之前顯示的圖像的預覽。


更新了答案:

試試這個JSFiddle example

HTML

<form name="" method="post" action="#" class="feedback-form-1"> 
    <fieldset> 
     <div class="input-file-row-1"> 
      <div class="upload-file-container"> 
       <img id="preview_image" src="#" alt="" /> 
       <div class="upload-file-container-text"> 
        <div class = 'one_opacity_0'> 
         <input type="file" id="patient_pic" label = "add" /> 
        </div> 
        <span> Add Photo </span> 
       </div> 
      </div> 
     </div> 
    </fieldset> 
</form> 

JQuery的:

function readURL(input, target) { 
    if (input.files && input.files[0]) { 
     var reader = new FileReader(); 
     var image_target = $(target); 
     reader.onload = function (e) { 
      image_target.attr('src', e.target.result).show(); 
     }; 
     reader.readAsDataURL(input.files[0]); 
    } 
} 

$("#patient_pic").live("change",function(){ 
    readURL(this, "#preview_image") 
}); 

CSS:

.input-file-row-1:after { 
    content: "."; 
    display: block; 
    clear: both; 
    visibility: hidden; 
    line-height: 0; 
    height: 0; 
} 

.input-file-row-1{ 
    display: inline-block; 
    margin-top: 25px; 
    position: relative; 
} 

#preview_image { 
    display: none; 
    width: 90px; 
    height: 90px; 
    margin: 2px 0px 0px 5px; 
    border-radius: 10px; 
} 

.upload-file-container { 
    position: relative; 
    width: 100px; 
    height: 137px; 
    overflow: hidden; 
    background: url(http://i.imgur.com/AeUEdJb.png) top center no-repeat; 
    float: left; 
    margin-left: 23px; 
} 

.upload-file-container-text{ 
    font-family: Arial, sans-serif; 
    font-size: 12px; 
    color: #719d2b; 
    line-height: 17px; 
    text-align: center; 
    display: block; 
    position: absolute; 
    left: 0; 
    bottom: 0; 
    width: 100px; 
    height: 35px; 
} 

.upload-file-container-text > span{ 
    border-bottom: 1px solid #719d2b; 
    cursor: pointer; 
} 

.one_opacity_0 { 
    opacity: 0; 
    height: 0; 
    width: 1px; 
    float: left; 
} 
+0

我試過了,但它不起作用http://jsfiddle.net/YJG79/11/ – Heidel

+0

我意識到你只是想幫助,但只是從另一個(鏈接)發佈代碼[答案](http:// stackoverflow.com/questions/4459379/preview-an-image-before-it-is-uploaded/4459419#4459419)沒有任何歸屬不是我們如何操作[so]。您需要正確說明您從何處獲取代碼。 – Lix

+0

@海德爾我在自己的應用程序中使用了相同的代碼,它的工作原理非常好。我會試着用你的例子試一下,讓你很快知道。 – Swati