我无法打开我的模态。我尝试了在Bootstrap 4站点上找到的纯HTML,然后使用了一些Javascript。我真的无法弄清楚我做错了什么。非常感谢任何帮助!
var addon = require('bindings')('addon');
function foo() {
console.log("woohoo!");
}
addon.setCallback(foo);
addon.call();
addon.callThis(() => console.log("this too!"));
<
enter code here
<div class="col-sm-3 col-centered boxes" id="box1">
<button type="button" class="btn btn-primary" id="box1modal" data-toggle="modal" data-target="#exampleModal">
See More
</button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Wedding Invites</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<img src="Wedding%20Invites.jpg">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</div>
`enter code here`<script type="text/javascript">
$(“#box1modal”)。click(function(event){
enter code here
$( '#myModal')模态( '显示')。
enter code here
)};
答案 0 :(得分:1)
如果您使用的是bootstrap,则不需要额外的scripting.bootstrap本身提供了运行不同动画和动作的脚本。我检查了你的代码。 错误在于行
<button type="button" class="btn btn-primary" id="box1modal" data-toggle="modal" data-target="#exampleModal">
看到你将数据目标设置为#exampleModal,而你的模态的id是“myModal”。只需将上面的代码改为
即可 <button type="button" class="btn btn-primary" id="box1modal" data-toggle="modal" data-target="#myModal">
没有任何其他脚本,它将正常工作。 希望这有助于......
答案 1 :(得分:0)
您已将数据目标设为examplemodal,将div的ID设为mymodal。两者都应该是一样的,这就是问题所在。
答案 2 :(得分:-1)
我测试你的代码,每件事都很好,你必须确保
1)添加引用 2)你的代码必须在$(document).ready(function(){----}
里面<html>
<head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="col-sm-3 col-centered boxes" id="box1">
<button type="button" class="btn btn-primary" id="box1modal" data-toggle="modal" data-target="#exampleModal">
See More
</button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Wedding Invites</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<img src="Wedding%20Invites.jpg">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</div>
</body>
</hmtl>
<script>
$(document).ready(function(){
$('#box1modal').click(function(){
alert("btn click")
$('#myModal').modal('show')
});
});
</script>