2

我正在使用Galleria,我需要将 Galleria 放入带有链接的幻灯片中的图像包装起来。

我打算使用这种方法:给出<img>一个虚假的title=值,然后<a>在 周围附加一个标签<img>,从标签中绘制我需要的链接title=

这是我到目前为止的代码。

$("img#gallery").this.title.appendTo("img#gallery") { });

我试图让脚本循环遍历所有图像并附加 html。

我也不知道我是否应该使用.appendToor .beforeand.after

4

3 回答 3

2

这种方法会奏效。您正在寻找 wrap 功能:

var title = $('#test').attr('title');

$('#test').wrap('<a href="'+title+'" />');

这 $.each 将让您遍历一个系列:

<img src="" class="test" alt="test" title="http://www.google.com" />
<img src="" class="test" alt="test" title="http://www.yahoo.com" />

$.each($(".test"), function() {
    var title = $(this).attr('title');
    $(this).wrap('<a href="'+title+'" />');
});
于 2011-01-26T19:04:14.537 回答
0

您可以只听整个事物的点击,然后确定是否单击了图像,如果是,则更改位置对象。

于 2011-01-26T19:02:30.073 回答
0

使用 $.each 遍历所有要包装的图像,然后使用

$('img#gallery').wrap('<a href='whatever'>) 

把它包起来。它将自动关闭 A 标签。

于 2011-01-26T19:08:11.480 回答