gpt4 book ai didi

JQuery 在 周围添加标签

转载 作者:行者123 更新时间:2023-12-03 22:53:51 31 4
gpt4 key购买 nike

如何使用 JQuery 添加带有指向该图像的链接的标签?

最佳答案

这将包装一组图像及其链接:

$('some selector for the images').each(function() {
$(this).wrap("<a href='" + this.src + "'/>");
});

...使用 .each ( link )、.wrap ( link ) 和 native DOM src ( link ) 图像元素的属性。

编辑 或者正如 Pointy 指出的那样(但不是明确指出的),只需将一个函数传递到 wrap 中即可:

$('some selector for the images').wrap(function() {
return "<a href='" + this.src + "'/>";
});

Live example

关于JQuery 在 <img> 周围添加标签 <a>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3987422/

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