T.J*_*der 21
这将包含一组带有链接的图像:
$('some selector for the images').each(function() {
$(this).wrap("<a href='" + this.src + "'/>");
});
Run Code Online (Sandbox Code Playgroud)
...使用.each(链接),.wrap(链接)和图像元素的本机DOM src(链接)属性.
编辑或Pointy指出(但没有尖锐),只需将一个函数传递给wrap:
$('some selector for the images').wrap(function() {
return "<a href='" + this.src + "'/>";
});
Run Code Online (Sandbox Code Playgroud)
$('#img').each(function(){
var $this = $(this);
$this.wrap('<a href="' + $this.attr('src') + '"></a>');
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12664 次 |
| 最近记录: |