想要在单击删除链接时删除添加到缩略图中的图像
Want to delete the images being added to the thumbnails when clicked on the delete link
图像被添加为缩略图,但删除操作的代码无法工作。这是我的代码
"span.innerHtml"中出现了问题,我知道。。。但无法解决
将删除操作作为delete as链接的脚本运行良好。。。。但当与图像集成为缩略图时,它无法工作。。。。
//select the files to be added
<input type="file" id="files" name="files[]"/>
<output id="list"></output>
//code for delete operation(after onClick)
<script>
$(document).ready(function(){
$('a.delete').on('click',function(e){
e.preventDefault();
imageID = $(this).closest('.image')[0].id;
alert('Now deleting "'+imageID+'"');
$(this).closest('.image')
.fadeTo(300,0,function(){
$(this)
.animate({width:0},200,function(){
$(this)
.remove();
});
});
});
});
</script>
//code to add images to thumbnails(before onClick)
<script>
function handleFileSelect(evt) {
var files = evt.target.files; // FileList object
// Loop through the FileList and render image files as thumbnails.
for (var i = 0, f; f = files[i]; i++) {
// Only process image files.
if (!f.type.match('image.*')) {
continue;
}
var reader = new FileReader();
// Closure to capture the file information.
reader.onload = (function(theFile) {
return function(e) {
// Render thumbnail.
var span = document.createElement('span');
span.innerHTML = ['<a href="#" class="delete">Delete<img class="thumb" src="', e.target.result,
'" title="', escape(theFile.name), '" width="110" height="150"/></a>'].join('');
document.getElementById('list').insertBefore(span, null);
};
})(f);
// Read in the image file as a data URL.
reader.readAsDataURL(f);
}
}
document.getElementById('files').addEventListener('change', handleFileSelect, false);
</script>
如果它以某种方式工作,并且不适用于动态添加的图像,则应该更改以下内容:
$('a.delete').on('click',function(e){...
至
$(document).on('click','a.delete', function(e){...
这个选择器也不正确,因为你没有名为"image"的css类:
$(this).closest('.image')
它应该是(将其更改为查找,因为它是一个子元素):
$(this).find('img')
否则,请分享一些细节,它是如何不起作用的。有错误吗?
在修复了我写的所有内容后,它就开始工作了(所以谢谢你的减号):http://jsfiddle.net/balintbako/EdkHN/
此外,您可能还想删除整个跨度:http://jsfiddle.net/balintbako/EdkHN/1/
相关文章:
- 使用php或javascript从facebook相册URL中删除多余的部分
- RegEx删除空属性?例如,如果(class=“”||class=“”)移除;否则就下课
- 如何删除多行HTML排列中的空白
- 如何从rails中的代码中删除新行( )
- 删除对HTML元素的拖动
- 当图像转换为本地存储的DataURL时,EXIF被删除
- 按顺序添加和删除类
- iframe正在添加标签,需要删除它们
- 如何在HTML输入字段中添加不可删除的后缀
- addData()从最新图表中删除.js 2.1.3-怎么了
- 如何覆盖锚点元素's href目标,并在我点击转到目标javascript时删除其他错误
- 通过点击按钮翻转缩略图
- 删除CKEditor工具栏按钮,但不删除功能
- 如何删除视频's缩略图时's加载在JW Player's闪光模式
- Dropzone-自动删除未接受文件的缩略图
- 想要在单击删除链接时删除添加到缩略图中的图像
- 如何在手动删除某些项目后刷新引导程序缩略图
- 如何完全删除任何类型的缩略图使用Jquery FileUpload库
- 单击下一个缩略图时删除内联样式
- 为每个图像缩略图预览添加删除按钮