这是我的html (我使用Galleria图片库-基于JQuery )
<div id="galleria">
<img alt="Productname 1" src="bens_img/1.jpg">
<img alt="Productname 2" src="bens_img/2.jpg">
<img alt="Productname 3" src="bens_img/3.jpg">
<img alt="Guess what?" src="bens_img/4.jpg">
</div>伪码
Get string from <alt> from <img>
Create a new <li> and paste the <alt> string from <img> in it这应该使用所有(例如:四个) img alt字符串来完成。它应该看起来像这样:
<ul class="textformat">
<li>Productname 1</li>
<li>Productname 2</li>
<li>Productname 3</li>
<li>Guess what?</li>
</ul> <!-- yeah this was all done by java-script -->发布于 2010-11-22 16:09:59
如下所示:
$("#galleria > img").each(function(i, ele) {
$(".textformat").append("<li>"+$(ele).attr("alt")+"</li>");
});发布于 2010-11-22 16:11:19
$("img[alt]")for标记所有具有'alt‘的图像
发布于 2010-11-22 16:16:36
您需要.attr jQuery选择器:
$('#galleria > img').each(function(){
$('.textformat').append('<li>'+ $(this).attr('alt') +'</li>');
});或者您可以使用$('#galleria').find('img')或$('#galleria').children('img')
https://stackoverflow.com/questions/4243468
复制相似问题