哦,太慢了,这是另一种添加类和计数方法(使用 div 而不是图像):)
http://jsfiddle.net/9T6xe/2/
HTML:
<div class="click-me">1</div>
<div class="click-me">2</div>
<div class="click-me">3</div>
<div class="click-me">4</div>
JS:
$(function() {
//elements to be clicked
var $div = $('.click-me');
//check if everyt div has been clicked, by checking if the num of elements with class done is equal to amount of elements
function everyDivAlreadyclicked() {
return $div.filter('.done').length === $div.length;
}
$div.bind('click', function() {
//add done class
$(this).addClass('done').text('clicked');
if (everyDivAlreadyclicked()) {
//if every div was clicked, profit!
alert('yay done!');
}
});
});