2014-06-27 42 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