我曾尝试过引导模态,但其按钮不起作用。请帮忙 谢谢你
我的代码不起作用:
<body>
<div class="quit_modal" tabindex="-1" role="dialog" data-toggle="modal" data-target="quit_model">
<div class="modal-dialog" id="delete-file-modal" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Modal title</h5>
<button type="button" class="btnClose" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="container-fluid">
<div class="row">
<div class="col-md-4 ml-2"></div>
<button type="button" class="btn btn-secondary"><a id="close" data-dismiss="modal" data-target="#quit_modal">Close</a></button>
<button type="button" class="btn btn-danger">Button</button>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="js/jquery-3.3.1.min.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<script type="text/javascript">
$("quit_Modal").modal('show');
$('btnClose').trigger('click');
</script>
</body>
答案 0 :(得分:1)
您当前没有类.
或标识符#
符号的选择器(“ quit_Modal”和'btnClose')将引用标签,因此jQuery将搜索名称为{{1 }}和<quit_Modal>
在您的DOM中。
您缺少选择器符号(点<btnClose>
和.
):
#
注意::$("#quit_Modal").modal('show');
$('.btnClose').trigger('click');
应该是ID quit_Modal
。
id="quit_Modal"
jQuery(document).ready(function(e) {
$("#quit_Modal").modal('show');
setTimeout(function() {
$('.btnClose').trigger('click');
}, 1000);
});
答案 1 :(得分:0)
您的选择器错误。
代替:
$("quit_Modal").modal('show');
$('btnClose').trigger('click');
使用此:
$(".quit_Modal").modal('show');
$('.btnClose').trigger('click');
答案 2 :(得分:0)
$("quit_Modal").modal('show');
$('btnClose').trigger('click');
两者都是类,因此请先在其之前放置点(。)...
$(".quit_Modal").modal('show');
$('.btnClose').trigger('click');