2014-06-27 88 views
0

我一直在努力嘗試,但沒有獲勝。HTML/jQuery幫我用這段代碼?

我有一個按鈕和一個div。當用戶點擊該按鈕時,文件瀏覽器打開並允許用戶選擇圖像。圖像被添加到div。這是前面的圖像。

我已經得到了代碼。但我也想複製控件,以便用戶可以添加圖像。但這似乎並不奏效。幫我修復代碼

OR

如果你們能提出一些更好的選擇,那麼這將是驚人的。

這裏的jsbin演示:

http://jsbin.com/pulug/1/

HTML :::

<html> 
    <head> 
     <script src="http://code.jquery.com/jquery-latest.js"></script> 
    </head> 
    <body> 
     <fieldset> 
      <legend>Choose Front Image</legend> 
      <input type=file id='file' class="button" onchange="startRead()"/> 
      <div id="dragherefront" >Drop files here</div> 
      <div id="manualfront"></div> 
     </fieldset> 
     <fieldset> 
      <legend>Choose Back Image</legend> 
      <input type=file id='file' class="button" onchange="startRead()"/> 
      <div id="draghereback" >Drop files here</div> 
      <div id="manualback"></div> 
     </fieldset> 
    </body> 
    </html> 

CSS ::

#dragherefront{ 
    width: 128px; 
    height: 128px; 
    background-color: rgba(221,214,155,0.4); 
    border: 1px dashed black; 
    text-align: center; 
    position: absolute; 
    opacity: 0; 
    overflow: hidden; 
} 

#draghereback{ 
    width: 28px; 
    height: 128px; 
    background-color: rgba(221,214,155,0.4); 
    border: 1px dashed black; 
    text-align: center; 
    position: absolute; 
    opacity: 0; 
    overflow: hidden; 
} 

#manualfront{ 
    width: 128px; 
    height: 128px; 
    overflow: hidden 
    background-color: rgba(221,214,221,0.3); 
    border: 1px dashed black; 
    overflow: hidden; 
    z-index: 0; 
} 

#manualback{ 
    width: 128px; 
    height: 128px; 
    overflow: hidden 
    background-color: rgba(221,214,221,0.3); 
    border: 1px dashed black; 
    overflow: hidden; 
    z-index: 0; 
} 
+1

請將您的問題縮小到您的代碼的特定區域,並在您的問題中提供該代碼 – charlietfl

+2

「幫我修復代碼」**否**至少直到您有意識地嘗試自行修復它,在你的問題中包含了相關的代碼,並且在代碼應該做什麼的時候增加了很多_far_更多的細節 – Bojangles

+0

我已經提供了jsbin演示,但無論如何我都給出了代碼。 – user3716080

回答

2

兩個輸入端具有相同的ID file。您無法複製代碼1:1,您需要更改ID(例如,將其設置爲第一個代碼snipet爲file1,第二個設置爲file2)。與divs相同。你必須重新編寫一段代碼,以便它可以處理多字段。

+0

我嘗試了所有這一切,但也沒有完美的工作。 – user3716080

+1

@ user3716080你不明白你在那裏的JS代碼,是嗎?不要理解我的錯誤,但正如我所說的,你不能僅僅複製HTML,改變ID,你還需要一些JS代碼的工作。 – nbar

+0

不完全。我剛開始學習。 – user3716080