且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

JQuery删除图像

更新时间:2023-12-05 18:33:40

这样做:

$("#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.

http://api.jquery.com/remove/

.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).