Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/397.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 两秒后删除信息消息_Javascript_Jquery_Html - Fatal编程技术网

Javascript 两秒后删除信息消息

Javascript 两秒后删除信息消息,javascript,jquery,html,Javascript,Jquery,Html,我有一个代码,在页面顶部提供用户信息消息, 目前它在那里,直到用户点击X按钮,我的问题是,如果有一个方法 若用户未单击X,则在2秒后自动删除此消息 function addessage(message) { $messages.html("<div class='alert alert-info'><strong>Information : </strong>" + message + "<button type='button'

我有一个代码,在页面顶部提供用户信息消息, 目前它在那里,直到用户点击X按钮,我的问题是,如果有一个方法 若用户未单击X,则在2秒后自动删除此消息

   function addessage(message) {
        $messages.html("<div class='alert alert-info'><strong>Information : </strong>" + message + "<button type='button' class='close' aria-hidden='true'>&times;</button></div>");
    }
功能附加消息(消息){
$messages.html(“信息:”+message+“×;”);
}
使用设置超时

function addessage(message) {
    $messages.html("<div class='alert alert-info'><strong>Information : </strong>" + message + "<button type='button' class='close' aria-hidden='true'>&times;</button></div>");
    setTimeout(function () {
        $messages.empty();
    }, 2000);
}
功能附加消息(消息){
$messages.html(“信息:”+message+“×;”);
setTimeout(函数(){
$messages.empty();
}, 2000);
}
使用设置超时

function addessage(message) {
    $messages.html("<div class='alert alert-info'><strong>Information : </strong>" + message + "<button type='button' class='close' aria-hidden='true'>&times;</button></div>");
    setTimeout(function () {
        $messages.empty();
    }, 2000);
}
功能附加消息(消息){
$messages.html(“信息:”+message+“×;”);
setTimeout(函数(){
$messages.empty();
}, 2000);
}
尝试使用以下方法:

尝试使用以下方法:

试试这个

function addessage(message) {
    $messages.html("<div class='alert alert-info'><strong>Information : </strong>" + message + "<button type='button' class='close' aria-hidden='true'>&times;</button></div>");

    setTimeout(function(){$('.alert.alert-info').fadeOut();}, 2000);
}
功能附加消息(消息){
$messages.html(“信息:”+message+“×;”);
setTimeout(函数(){$('.alert.alert info').fadeOut();},2000);
}
试试这个

function addessage(message) {
    $messages.html("<div class='alert alert-info'><strong>Information : </strong>" + message + "<button type='button' class='close' aria-hidden='true'>&times;</button></div>");

    setTimeout(function(){$('.alert.alert-info').fadeOut();}, 2000);
}
功能附加消息(消息){
$messages.html(“信息:”+message+“×;”);
setTimeout(函数(){$('.alert.alert info').fadeOut();},2000);
}

谢谢,我可以将淡出更改为更慢吗?是的,您可以提供毫秒级的时间,如
。淡出(1000)
一秒钟,或者您也可以这样做,如
。淡出(“慢”)
。谢谢,我可以将淡出更改为更慢吗?是的,您可以提供毫秒级的时间,如
。淡出(1000)
一秒钟,或者你也可以像
.fadeOut('slow')
那样做。