我想从模板中获取每个项目。模板如下所示:
<div class="row flush" id="photos_list">
<script id="photo_list_template" type="text/x-handlebars-template">
{{#each this}}
<div class="3u photo">
<img src="{{url}}" alt="{{name}}"/>
</div>
{{/each}}
</script>
</div>
现在我想获取每个 img,并在悬停时显示 alt 和黑色背景,但我似乎无法让它工作,以获取元素。我想要类似的东西:
$('div.row').find('img').hover(function(){
//some code
})
这是生成的html:
<div class="row flush" id="photos_list">
<div class="3u photo">
<img src="http://everythingawesomeever.files.wordpress.com/2013/07/awesome-meter.jpg" alt="Again, with the insanity.">
</div>
<div class="3u photo">
<img src="http://who-is-awesome.com/who-is-awesome.jpg" alt="Who's awesome?">
</div>
<div class="3u photo">
<img src="http://www.miataturbo.net/attachments/insert-bs-here-4/78009-my-little-random-picture-thread-*sfw-huffy-*-1682345-slide-slide-1-biz-stone-explains-how-he-turned-91-random-photos-into-movie-jpg?datelin" alt="After Mask">
</div>
<div class="3u photo">
<img src="http://www.miataturbo.net/attachments/insert-bs-here-4/76756-my-little-random-picture-thread-*sfw-huffy-*-11254201pkm5958-jpg?dateline=1368653578" alt="English Muffin">
</div>
</div>
我该怎么做?