我有重置 setTimeout 的问题。我尝试使用clearTimeout():
function formMsg(text){
if (text == "success"){
$( ".alert-msg" ).removeClass( "hidden alert-danger" ).addClass( "alert-success" );
$( ".alert-success .msg" ).html( "<b>Well done!</b> You successfully added order." );
} else {
$( ".alert-msg" ).removeClass( "hidden alert-success" ).addClass( "alert-danger" );
$( ".alert-danger .msg" ).html( "<b>F***!</b> Something went wrong." );
}
window.clearTimeout(timer);
var timer = window.setTimeout(function()
{
$(".alert-msg").fadeOut("slow", function() {
$(this).addClass('hidden').show(0);
});
}, 2000);
}
但没有结果。我希望当您单击时,计时器再次测量了两秒。