点击后我有一个链接打开一个带有表单的引导模式:
<a href="#number_form_1" role="button" data-toggle="modal" style='color:white' id="schedule">Click To Fill</a>
问题是我想通过Jquery触发模态而不是这样。所以当我将上面的链接更改为如下按钮时:
<button id="form1" role="button" data-toggle="modal">Click To Fill</button>
用户jquery在document.ready中如下:
$("#form1").click(function(){
$('#number_form_1').modal('show');
});
弹出窗口不起作用。我已尽一切可能找出问题,但它不起作用。我甚至在$("#form1").click(function(){
之后发出警告并且它有效,但模态没有。
请建议。
答案 0 :(得分:2)
data-toggle="modal"
$('#myModal').modal('show');
中使用按钮的ID,此处myModal是模态的ID。<强> HTML 强>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-lg">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
<强> JS 强>
$('button').click(function(){
$('#myModal').modal('show');
});
答案 1 :(得分:0)
你只需要将表单放在模态中,然后在Jquery中调用它:
$(document).ready(function() {
$("#form1").click(function () {
$('#myModal').modal({
show: true
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet"/>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true" id="myModal">
<div class="modal-dialog modal-lg">
<div class="modal-content">
.....
</div>
</div>
</div>
<button id="form1" role="button" data-toggle="modal">Click To Fill</button>