如何引导模态显示Alert

问题描述:

如何引导模态显示Alert

$(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>

我想显示在引导模态警报。

+0

不能包含JS警告框。如果你想要一个模式的警告框,使用CSS/HTML设计它,并使用JS/jQuery触发它。 – Tushar

+0

有关使用引导程序创建模式的一些信息http://www.w3schools.com/bootstrap/bootstrap_modal.asp http: //getbootstrap.com/javascript/#modals – spaceman

+0

你是否试图在内部显示一个带有“alert”文本的模式?或者你是否试图从模式中的链接触发浏览器警报? – cbronson

创建模式体错误股利。并设置错误

$(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函数在页面元素中显示消息。 Alert在页面dom外显示系统警报。

如果要在模态中显示消息,则必须在页面html中包含(或注入)模式标记,然后只需通过引导程序功能显示/隐藏模式。

你有一个很好的例子here