我要做的就是根据我编写的计数脚本的结果使 div 淡出。一切正常,但唯一不能正常工作的是当值返回到名为计数器的 div 时 div 淡出。这是一个 jsfiddle - http://jsfiddle.net/andyjh07/fBqRK/,javascript代码如下:
jQuery -
$('#trigger').on('click', function(){
// Count all of the checked boxes and then output the result
var count = $("[type='checkbox']:checked").length;
var fadespeed = 500;
$('#counter').text(count).fadeIn(fadespeed);
// Now, depending on the results, display some stuff
var message = $('#message');
if(count >= 8){
message.fadeIn(fadespeed).text('You have done really well');
} else if (count >= 4) {
message.fadeIn(fadespeed).text('You are sort of okay');
} else {
message.fadeIn(fadespeed).text('You are terrible, sorry.')
}
});
if($('#counter').text() == 2){
$('#buttons').fadeOut(500);
}
HTML -
<input type="checkbox" value="Yes"/>
<input type="checkbox" value="Yes"/>
<input type="checkbox" value="Yes"/>
<input type="checkbox" value="Yes"/>
<input type="checkbox" value="Yes"/>
<input type="checkbox" value="Yes"/>
<input type="checkbox" value="Yes"/>
<input type="checkbox" value="Yes"/>
<input type="checkbox" value="Yes"/>
<input type="checkbox" value="Yes"/>
<div id="trigger">Click to count 'em</div>
<div id="counter"></div>
<div id="message"></div>
<div id="buttons">Buttons</div>