如何在提交代码时从 PHP 切换此模式?
How to toggle this modal from PHP on submit code?
我有这个模式:
<div class="container">
<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">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
我想在执行一些 PHP 代码时切换它
if(//){
//toggle modal
}
到目前为止我尝试的是在执行函数时将标志设置为 true 然后在 html 我这样做:
<?php if ($show_modal) : ?>
<script>
$('#myModal').modal('show');
</script>
<?php endif; ?>
但还是不行。有人知道这是怎么回事吗?
编辑:我在 html header
中加载的所有插件
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="../style.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.min.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
因为你设置了两次jquery插件,可能会越来越难。所以,在我看来你有两个选择。首先,您可以将 bootstrap 插件移至底部并删除其中一个 jquery 插件。就在 body 结束之前。喜欢:
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<?php if ($show_modal) : ?>
<script>
$('#myModal').modal('show');
</script>
<?php endif; ?>
或者,您可以使用:
$(document).ready(function(){
// Here goes yor code
});
当你导入bootstrap,并再次添加jquery插件。您必须使用 document.ready
以确保所有文件都已加载,然后我们将使用该功能。
*注意:- 如果您移动 bootstrap.js,您可能还必须在 bootstrap 之后移动 jquery table 插件。我不确定,因为我还没有使用那个插件。
我有这个模式:
<div class="container">
<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">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
我想在执行一些 PHP 代码时切换它
if(//){
//toggle modal
}
到目前为止我尝试的是在执行函数时将标志设置为 true 然后在 html 我这样做:
<?php if ($show_modal) : ?>
<script>
$('#myModal').modal('show');
</script>
<?php endif; ?>
但还是不行。有人知道这是怎么回事吗?
编辑:我在 html header
中加载的所有插件 <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="../style.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.min.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
因为你设置了两次jquery插件,可能会越来越难。所以,在我看来你有两个选择。首先,您可以将 bootstrap 插件移至底部并删除其中一个 jquery 插件。就在 body 结束之前。喜欢:
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<?php if ($show_modal) : ?>
<script>
$('#myModal').modal('show');
</script>
<?php endif; ?>
或者,您可以使用:
$(document).ready(function(){
// Here goes yor code
});
当你导入bootstrap,并再次添加jquery插件。您必须使用 document.ready
以确保所有文件都已加载,然后我们将使用该功能。
*注意:- 如果您移动 bootstrap.js,您可能还必须在 bootstrap 之后移动 jquery table 插件。我不确定,因为我还没有使用那个插件。