我正在尝试使用 jquery 将列表中图像的所有 id 标签存储在一个数组中。
到目前为止,我有这个:
HTML
<div id="trash" class="ui-widget-content grid_8 ui-droppable">
<ul class="gallery ui-helper-reset">
<li class="" style="display: block; width: 48px;">
<img id="22" src="data:image/jpeg;base64," width="96" height="72" style="display: inline-block; height: 36px;">
</li>
<li class="" style="display: block; width: 48px;">
<img id="24" src="data:image/jpeg;base64," width="96" height="72" style="display: inline-block; height: 36px;">
</li>
<li class="" style="display: block; width: 48px;">
<img id="23" src="data:image/jpeg;base64," width="96" height="72" style="display: inline-block; height: 36px;">
</li>
</ul>
</div>
<div id="stored" style=""></div>
查询
$(document).ready(function() {
$('#trash').click(function(){
var imglen = $('#trash li img');
var aux = [];
for (var i = 0; i < imglen.length; i++) {
aux.push(imglen[i].attr("id"));
}
$('#stored').text(aux.join(" "));
});
});
它没有显示任何东西。我只需要使用下面的代码显示第一个 img id:
$('#trash').click(function(){
$('#stored').html($('#trash li img').attr("id"));
});