gpt4 book ai didi

jquery - 从 HTMLImageElement 对象获取图像源

转载 作者:行者123 更新时间:2023-12-01 00:37:33 24 4
gpt4 key购买 nike

我有以下 jQuery,我想输出图像列表。问题是我无法通过“this”找到来源。它当前是一个输​​出为 HTMLImageElement 的对象。如何从该对象获取图像源?

$("#imgs li.images img").each(function(i) { 
$("#list").append("<li><img src=\""+this.attr("src")+"\" /></li>");
});

我当前收到错误:this.attr 不是函数。

最佳答案

this 是 DOMNode,而不是 jQuery 对象。您可以立即访问 this.src ,或者,如果您想使用 jQuery,$(this).attr('src') ,尽管这样做会绕道同样的事情。

关于jquery - 从 HTMLImageElement 对象获取图像源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2508884/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com