也许我理解错了,但这种情况不应该在这种情况下起作用吗?我做错了什么?
$("#count").on("click", function(){
$(".item").each(function( index, element ){
$(element).text( index + 1 );
/*** this line does nothing ****/
$(element).has(".special").css("background", "black");
if( index + 1 == 4 || index + 1 == 8 ){
$(this).css("background", "#A5C663");
}
})
})
HTML:
<div id="grid">
<div class="item"></div>
<div class="item special"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item special"></div>
<div class="item"></div>
</div>
这也不起作用:
$(this).has(".special").css("background", "black");
或者:
$(".item).has(".special").css("background", "black");