$('.test-item').each(function(){ var selectedLable = $(this).children('ul:first').children("li:gt(0)"); var title = $(this).children('ul:first').children("li:first").children('div:first'); var isNeedShowAlert = true; selectedLable.each(function(){ var item = $(this).children('div:first'); var ulClass =item.attr('class'); if(ulClass){ if(ulClass.indexOf("on")!=-1){ var temp = $(this).attr("val"); isNeedShowAlert = false; } } }); if(isNeedShowAlert){ title.attr("style","display: block;"); } else{ title.attr("style","display: hidden"); } }); $('.test-item') 选择所有class="test-item"的元素 .each()进行遍历 $(this).children('ul:first').children("li:gt(0)");遍历子元素的第一个<ul></ul>的大于0的<li></li>标签元素