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