【问题标题】:Load a modal if a session exists is not working如果会话存在则加载模式不起作用
【发布时间】:2018-06-06 17:25:41
【问题描述】:

如果会话存在,我想显示一个模式,我试过这样但它没有显示

<?php if(isset($_SESSION['Message1'])) { ?>
<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-hidden="true">&times;</button>
    <h4 class="modal-title" id="myModalLabel">Welcome...</h4>
  </div>
  <div class="modal-body">
    This is test 
  </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>
<script type="text/javascript">
  $(window).load(function(){        
  $('#myModal').modal('show');
}); 
</script>
<?php } ?>

提前感谢

【问题讨论】:

  • 你看到了什么?控制台输出什么?是否包含引导脚本和 css?
  • 请定义“它不起作用”。
  • if(!empty($_SESSION['Message1'])) 使用 this 而不是 isset()。
  • 仍然没有显示模态
  • 一旦删除会话条件并检查它是否显示。可能还有其他问题然后会话。还要检查是否在 html 中加载了模态。

标签: javascript php html bootstrap-modal


【解决方案1】:

也许这会对你有所帮助。

代替$(window).load()试试

$( "#myModal" ).load(function() {
  $('#myModal').modal('show');
});

【讨论】:

  • 你是否尝试在没有任何负载的情况下使用 juts ` $('#myModal').modal('show');` ?
  • 也看看这个答案也许它会帮助你stackoverflow.com/a/36672567/4553685
  • 我怎么看到&lt;div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria- labelledby="myModalLabel" aria-hidden="true"&gt; 中有一个aria-hidden="true" 你能把它删掉再试一次吗
【解决方案2】:

您刚刚忘记开始会话。 所以在你检查会话之前添加了这一行。

session_start();

【讨论】:

  • session_start();已添加到我的页面中,但我忘记添加我的问题
  • 您好,删除$(window).load(function(){
猜你喜欢
  • 1970-01-01
  • 2014-07-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-16
  • 2014-09-10
  • 2018-02-05
相关资源
最近更新 更多