如何循环获取这个span里的data
发布网友
发布时间:2023-11-04 08:13
我来回答
共1个回答
热心网友
时间:2024-08-11 06:03
<li class='type_Label_Items'>
<span data-id='1'>aaa</span><span>1</span><span>2</span>
</li>
<li class='type_Label_Items'>
<span data-id='2'>aaa</span><span>1</span><span>2</span>
</li>
<li class='type_Label_Items'>
<span data-id='3'>aaa</span><span>1</span><span>2</span>
</li>
<script src=scripts/jquery-1.8.3.min.js></script>
<script>
/* jQuery */
$(function() {
$('.type_Label_Items').each(function() {
alert($(this).find('[data-id]').attr('data-id'));
})
//或
$('.type_Label_Items [data-id]').each(function() {
alert($(this).attr('data-id'));
})
});
</script>