需求:
第一次点击按钮,区块关闭,过3秒自动出现,第二次点击按钮,关闭,不再出现!!!
var flag = true;
$(".close1").click(function(){
if(flag){
$("#bt_active").hide();
setTimeout(function(){$("#bt_active").show()},3000);
flag=false;
}else{
$("#bt_active").hide();
}
});
写的不对,新手,求大神帮助!!!!
flag=false;
flag只有为false
,就不考虑把它再置为true
的情况?
if(flag){
$("#bt_active").hide();
flag=false;
setTimeout(function(){$("#bt_active").show();flag=true;},3000);
}
你在setTimeout中改变了按钮显示状态,但是没有重置flag的值,所以,setTimeout执行后,按钮显示,flag任然是false,就会一直执行$('#bt_active').hide()
看错需求了,楼上的答案就可以了