源代码
<div class="level_1 euItem generation_y _2012">
<img border="0" src="img2.jpg" class="euImg" alt="Run">
<a href="/sport/sport_2014/media_gallery/images/car.htm" class="lightview">Run</a>
</div>
<div class="level_1 euItem youth_forum">
<img border="0" src="img3.jpg" class="euImg" alt="Run">
<a href="/sport/sport_2014/media_gallery/images/aircraft.htm" class="lightview">Run</a>
</div>
我需要获取 div 元素的第三类并将其作为 A 元素的属性
结果代码:
<div class="level_1 euItem generation_y _2012">
<img border="0" src="img2.jpg" class="euImg" alt="Run">
<a href="/sport/sport_2014/media_gallery/images/car.htm" class="lightview" data-lightview-group="generation_y _2012">Run</a>
</div>
<div class="level_1 euItem youth_forum">
<img border="0" src="img3.jpg" class="euImg">
<a href="/sport/sport_2014/media_gallery/images/aircraft.htm" class="lightview" alt="Run" data-lightview-group="youth_forum">Run</a>
</div>
我现在在这一点上,但它不起作用。请注意,每个 div 都有一个我必须使用的不同类:
var lightviewGroup = $(this).attr('class').split(' ');
$('div.euBox div.level_1 h4 a.link-ico').attr('data-lightview-group',imgCaption[2]);