可关闭警告框

3
我正在尝试使警报框在点击“x”按钮后消失,但似乎缺少某些东西导致它无法正常工作,不确定是什么原因。
<div class="alert alert-success alert-dismissible">
<button type = "button" class="close" data-dismiss = "alert">x</button>
    You've done it!
</div>

1
你的问题只有在谈论Bootstrap时才有意义。请在提问时更加精确。 - yspreen
1个回答

7

要使用可关闭的功能,您需要在文档中包含jQuerybootstrap.js

 <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap 101 Template</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
<div class="alert alert-success alert-dismissible">
    <button type = "button" class="close" data-dismiss = "alert">x</button>
    You've done it!
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div style="margin-top: 50px" class="alert alert-success alert-dismissible">
    <button type = "button" class="close" data-dismiss = "alert">x</button>
    You've done it!
</div>


谢谢!我缺少了Jquery。 - Denise Walter

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接