簡體   English   中英

如何在Bootstrap模式中顯示警報

[英]How to display an Alert in Bootstrap Modal

 $(window).load(function(){ $('.alertbox').click(function(){ alert('You Clicked on Click Here Button'); }); }) 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"> </script> <div> <a class="alertbox" href="#clicked"> Click Here</a> </div> 

我希望警報顯示在引導程序模態中。

在模態體中創建錯誤div。 並設置錯誤

 $(document).ready(function(){ $('#alertbox').click(function(){ $("#error").html("You Clicked on Click here Button"); $('#myModal').modal("show"); }); }); 
 <!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.2.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"> <h2>Modal Example</h2> <!-- Trigger the modal with a button --> <button type="button" class="btn btn-info btn-lg" id="alertbox">Click here</button> <!-- Modal --> <div class="modal fade" id="myModal" role="dialog"> <div class="modal-dialog"> <!-- Modal content--> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">&times;</button> <h4 class="modal-title">Modal Header</h4> </div> <div class="modal-body"> <p id="error"></p> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> </div> </div> </div> </div> </div> </body> </html> 

可能我沒有正確理解你的問題,但是你不能使用alert函數在頁面元素中顯示一條消息。 警報在頁面dom外顯示系統警報。

如果要在模態中顯示消息,則必須在頁面html中包含(或注入)模態標記,然后只需通過引導函數顯示/隱藏模態。

在這里有一個很好的例子

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM