JQuery删除图像 [英] JQuery remove images
问题描述
我很好奇是否有人知道为什么这段jQuery代码不能删除图像?
I'm curious if anyone knows why this piece of jQuery code doesn't remove the images?
var a = $('#tblMain').clone().remove('img');
正在选择表格。这是试图在网页上取表并导出到Excel,但我不希望图像导出。
The table is being selected. This is trying to take the table on the webpage and export to excel but I do not want the images to export.
谢谢,
推荐答案
这样做:
$("#tblMain").clone().find("img").remove();
编辑:好的,这就是问题所在:
Okay, here's the problem:
selector:
过滤匹配元素集的选择器表达式
将被删除。
selector: A selector expression that filters the set of matched elements to be removed.
.remove('img')
中的 img
是过滤中的一组项目jquery对象,不是在项目本身中找到元素。在这种情况下,jquery对象只包含一个项目,克隆表。因此, .remove('img')
不会删除任何内容,因为jquery对象不包含任何图像(仅包含其中包含的项目中的图像)。
The img
in .remove('img')
is to filter the set of items in the jquery object, NOT to find elements within the items themselves. In this case, the jquery object contains only one item, the cloned table. Therefore, .remove('img')
removes nothing, since the jquery object does not contain any images (only images within items it contains).
这篇关于JQuery删除图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!