将多个图像上传到具有“;上传”;按钮
Issue uploading multiple images to a page with "upload" button...
我在这里有一个Fiddle。。。
我已经完成了在上传按钮下加载图像的功能,但是,如何将多个图像上传到同一页面?有三个地方我允许用户上传特定的图像。
<div class="element-file" title="Do you want to add an image to the Accreditation Text?">
<label class="title" style="font-weight: bold;">Add an image to the left of the Accreditation text<br>(Image will be resized to 100px by 100px)</label>
<label class="medium" >
<input type='file' onchange="readURL(this);" />
</label>
<p><strong>(Image will display below)</strong></p>
<div style="max-width: 100px; height: auto; border:1px dashed black;">
<img id="accred_image" src="accred" alt="" />
</div>
</div>
并将图像添加到此区域
<div class="element-file" title="Do you want to add an image to the Accreditation Text?">
<label class="title" style="font-weight: bold;">Would you like to add a logo image?</label>
<label class="medium" >
<input type='file' onchange="readURL(this);" />
</label>
<p><strong>(Image will display below)</strong></p>
<div style="max-width: 140px; height: auto; border:1px dashed black;">
<img id="blah" src="" alt="" />
</div>
</div>
这是我的javascript,但当我上传图像时,它会在两个位置放置相同的图像。我以为这与我上传的类有关,但创建新类似乎根本没有帮助
$("input").change(function(e) {
for (var i = 0; i < e.originalEvent.srcElement.files.length; i++) {
var file = e.originalEvent.srcElement.files[i];
var reader = new FileReader();
reader.onloadend = function() {
$('#accred_image').attr('src', reader.result);
}
reader.readAsDataURL(file); }
});
您需要找到要更新的img。试试这个:
$("input").change(function(e) {
var elemIMG = $(this).parent().parent().find('img'); // find the img to update
for (var i = 0; i < e.originalEvent.srcElement.files.length; i++) {
var file = e.originalEvent.srcElement.files[i];
var reader = new FileReader();
reader.onloadend = function() {
elemIMG.attr('src',reader.result); // update the img src
}
reader.readAsDataURL(file); }
});
相关文章:
- Javascript上传按钮问题,适用于Wordpress
- 我想在提交最终的 sibmit 按钮 saveBank() 之前验证上传按钮
- 取消图像上传按钮
- JS用于鼠标悬停图像上传按钮(如Facebook)
- 增加了“上传”按钮的文本字体大小
- 多个JavaScript上传按钮只将内容放在一个中
- 如何通过单击上传按钮在上传文件后重新加载 Jqgrid
- 在以前的更改时附加新的文件上传按钮
- 文件上传按钮在科尔多瓦/Phonegap项目中仍然不起作用
- 如何在拖放区.js中设置上传按钮
- 当我单击“上传”按钮时,没有任何反应
- 在文件上传按钮中显示文件的名称
- 当我单击“上传”按钮时,警报不会出现
- 上传按钮文本
- 将上传按钮从输入更改为跨度时,图像上传不起作用
- 如何将自定义css类分配给fineploader中的上传按钮
- 在现有上传按钮中附加进度条
- 如何将上传按钮的名称更改为请稍候.
- 当选择任何文件时,jQuery监听器上的“文件上传”按钮
- 如何删除nicEdit文本编辑器中的上传按钮