我试图提醒每个 div 的 id,以便它输出 11 25 78
。
<div id="main">
<div id="section-11">Some content</div>
<div id="section-25">Some content</div>
<div id="section-78">Some content</div>
</div>
我已经选择了 main
并且我正在尝试使用 children
但它不起作用。不知道为什么。
$('#main').children().each(function(){
alert($(this).attr('id'));
});
最佳答案
$('#main div').each(function() {
alert($(this).attr('id').replace(/section-/, ''));
});
关于javascript - 我如何选择这些子div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6090402/