[英]Alert box is not closing when trying to do so
我已經復制了此代碼,並出現了警告框,但是當我單擊“ x”時它似乎沒有關閉,這是代碼:
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" href="css/bootstrap.css">
<script src="js/jquery.js"></script>
<script src="js/bootstrap.js"></script>
</head>
<body>
<div class="container-fluid">
<div class="alert alert-danger">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>The File will be deleted!
</div>
</div>
</body>
</html>
庫: 這是我導入它們的方式
您的庫似乎是此代碼無法正常工作的問題,請對其進行檢查
<!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Example</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> </head> <body> <div class="container"> <div class="alert alert-success alert-dismissible"> <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a> <strong>Success!</strong> This alert box could indicate a successful or positive action. </div> </div> </body> </html>
您是否正確導入了jquery,Bootstrap (路徑)? 它為我工作。
<!DOCTYPE html> <html> <head> <title></title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> </head> <body> <div class="container-fluid"> <div class="alert alert-danger"> <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>The File will be deleted! </div> </div> </body> </html>
嘗試將腳本標簽從標題標簽移出,然后向下移到body標簽,緊接在結束body標簽之前。
將script標簽放在頭部被認為是不好的做法,因為它們可能在整個DOM加載之前運行。
問題:-您不包括將為您完成所有工作的bootstrap js文件
解決方案:-您應包括文件
請查看引導文檔https://getbootstrap.com/docs/4.0/components/alerts/#dismissing中的此鏈接
您會發現這條線
確保已加載警報插件或已編譯的Bootstrap JavaScript。
也嘗試將腳本文件放在HTML的底部
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <head> <title></title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> </head> <body> <div class="container-fluid"> <div class="alert alert-danger"> <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>The File will be deleted! </div> </div> </body>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.