$(function () {
var ptitle = $('div.portfolioItem div.image img').attr("title");
$(this).each(function () {
$('a.play').attr({
'title': '' + ptitle + ''
});
});
});
好吧,这是我的代码,它可以工作,但我对每个标签并不是很熟悉。
目前所做的只是将第一个“标题”应用于所有 a.play 标签。
我想要实现的是从每个图像中获取标题并将其仅应用于相关的 a.play 按钮。
如果这对理解有帮助,这里是 html:
<figure class="oneThird">
<div class="portfolioItem">
<div class="image">
<!-- This is the image -->
<img src="images/portfolio-item-2.jpg" alt="portfolio item" title="test2" />
<div class="info">
<p> Alright, go to the link Andrew propose. Download the file.
You need to add it to your project. You can still have
jquery.effects.core this is why this is random fill to
take space.
</p>
<span class="base">
<!-- Add the img title to the <a class="play"> below -->
<a href="images/header-image-2.jpg" rel="prettyPhoto[portfolio]" class="play"></a>
<a href="#" class="view">View Project</a>
</span>
</div>
</div>
</div>
<h3>
<a href="#">This is a portfolio item</a>
</h3>
<ul class="tags">
<li><a href="#">Web</a>, </li>
<li><a href="#">Print</a>, </li>
<li><a href="#">Design</a></li>
</ul>
</figure>
综上所述,代码已经生成了 a 标签的所有标题,但只生成了第一个标题并将其应用于所有 a 标签,我需要将整个页面中每个图像的标题应用到 a 标签中特定区域。
有任何想法吗?