I am having trouble getting a modal to display. I am using bootstrap 3.0.3. When I click the button, the screen goes grey but doesn't popup the modal. The css and js files are in the same directory as the html file. I know this code works because I copy and pasted it from http://www.tutorialrepublic.com/codelab.php?topic=bootstrap&file=activate-modals-via-javascript . So this makes me think that something is wrong with the way I declared my css and js files in the head. Any help would be much appreciated!
<!DOCTYPE html>
<html lang="en">
<head>
<title>Example of Twitter Bootstrap Modals</title>
<link rel="stylesheet" type="text/css" href="bootstrap.min.css">
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript" src="bootstrap.min.js"></script>
<script type="text/javascript">
$(function(){
$(".btn").click(function(){
$("#myModal").modal('show');
});
});
</script>
<style type="text/css">
.bs-example{
margin: 20px;
}
</style>
</head>
<body>
<div class="bs-example">
<!-- Button HTML (to Trigger Modal) -->
<a href="#" class="btn btn-large btn-primary">Launch Demo Modal</a>
<!-- Modal HTML -->
<div id="myModal" class="modal hide fade">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3>Confirmation</h3>
</div>
<div class="modal-body">
<p>Do you want to save changes you made to document before closing?</p>
<p class="text-warning"><small>If you don't save, your changes will be lost.</small></p>
</div>
<div class="modal-footer">
<a href="#" class="btn">Close</a>
<a href="#" class="btn btn-primary">Save changes</a>
</div>
</div>
</div>
</body>
</html>
You use class .hide at that have styles:
.hide{
display: none!
}
These rule always hide block
Better solution would be 1. Add special class for this:
.hide-block{
display: none;
}
<div id="myModal" class="modal hide-block fade">
2.The second way is to use inline styles
<div id="myModal" class="modal fade" style="display: none">
but this is not so good as the first solution
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.