Javascript 使用twitter发出警报';s引导在几秒钟后消失
我试图学习twitter的引导CSS框架来向用户发出一些警报,我想,在向用户显示警报后,警报会在3秒钟后消失。我编写了此代码,但不起作用,无法关闭警报,不明白我做错了什么:Javascript 使用twitter发出警报';s引导在几秒钟后消失,javascript,jquery,html,twitter-bootstrap,Javascript,Jquery,Html,Twitter Bootstrap,我试图学习twitter的引导CSS框架来向用户发出一些警报,我想,在向用户显示警报后,警报会在3秒钟后消失。我编写了此代码,但不起作用,无法关闭警报,不明白我做错了什么: <!DOCTYPE html> <head> <title>Alert in boostrap</title> <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/
<!DOCTYPE html>
<head>
<title>Alert in boostrap</title>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css">
<script type="text/javascript" src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script>
<script type="text/javascript">
window.setTimeout(function() {
$(".alert-message").fadeTo(500, 0).slideUp(500, function(){
$(this).remove();
});
}, 3000);
</script>
</head>
<body >
<br><br>
<div class="container">
<h1>This is a test</h1>
<div id="alert_message" class="alert" style="width:200px" >
<span class="close" data-dismiss="alert">×</span>
<span><strong>Atention!</strong> Responsive Design with Twitter Bootstrap.</span>
</div>
</div>
</body>
</html>
警觉
setTimeout(函数(){
$(“.alert message”).fadeTo(500,0).slideUp(500,function(){
$(this.remove();
});
}, 3000);
这是一个测试
&时代;
Atention具有Twitter引导功能的响应性设计。
ps:我是网络编程的新手,如果问题或错误非常明显或愚蠢,请耐心等待。非常感谢大家首先,您缺少jQuery库,请在
bootstrap.min.js
<script type="text/javascript" src="//code.jquery.com/jquery-1.10.2.min.js"></script>
您在这里有一个错误,
$(“.alert message”)
您是说您有一个名为“alert message”的类,但是您没有,您有并且没有id不是一个类,所以它应该是$(“#alert_message”)
消息被发送了
$(“.alert”).delay(4000).slideUp(200,function(){
$(此).alert('close');
});
看看这是一个使用jQuery和Bootstrap依赖项的功能极其丰富的警报插件。它有麻省理工学院的许可证
调用新通知就像调用<代码>$一样简单。notify(“Hello World”)但是你可以随心所欲地复杂,添加图像、图标、超链接、调整大小、重新设置样式。,我相信你正在寻找的是一个jquery插件或pnotify插件。一定要查看它们。:)
window.setTimeout(function() {
$("#alert_message").fadeTo(500, 0).slideUp(500, function(){
$(this).remove();
});
}, 3000);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div class="alert alert-success" id="success-alert">The message was sent</div>
<script>
$(".alert").delay(4000).slideUp(200, function() {
$(this).alert('close');
});
</script>