【问题标题】:bootstrap modal cookie not showing引导模式 cookie 未显示
【发布时间】:2017-02-06 17:04:07
【问题描述】:

我试图在页面加载时显示引导模式(仅 1 次)并设置 7 天的 cookie。但是有些东西阻止了模态的出现。如果我不使用 jquery-cookie,模式就会出现。我做错了什么?

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> 
<script src="js/jquery.cookie.js"></script>

<script type="text/javascript">
$(document).ready(function() {
  if ($.cookie('pop') == null) {
    $('#myModal').modal('show');
    $.cookie('pop', '7');
  }
});

<div class="modal fade in" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" id="myModal">
    <div class="modal-dialog modal-md">
    <!-- Modal content-->
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">&times;</button>
        </div>
        <div class="modal-body">
            test
        </div>
    </div>
</div>

【问题讨论】:

  • 在 if 语句之前尝试alert($.cookie('pop'));。如果在警告框中显示某些内容,则模式将不会显示为 $.cookie('pop') == null 将是 false,因此 if 语句将不会执行 $('#myModal').modal('show');

标签: javascript jquery twitter-bootstrap cookies bootstrap-modal


【解决方案1】:

添加警报($.cookie('pop'));没有做任何不同的事情。仍然没有弹出窗口或其他消息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-25
    • 2019-02-10
    相关资源
    最近更新 更多