简体   繁体   English

如何通过变量引导模式弹出窗口?

[英]How to bootstrap modal popup via a variable?

I am studying the bootstrap, and follow the example: 我正在研究引导程序,并按照示例进行操作:

<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
    Shows the modal
</button>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="false">
    <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">
                    模态框(Modal)标题
                </h4>
            </div>
            <div class="modal-body">
                在这里添加一些文本
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                </button>
                <button type="button" class="btn btn-primary">
                    提交更改
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

if I click the button the modal will popup, but I don't understand which variable is controlling the modal popup and disappear. 如果单击按钮,将弹出模式对话框,但我不知道哪个变量控制着模式弹出窗口并消失。

I want to through a variable to popup it. 我想通过一个变量来弹出它。 there is a requirement. 有一个要求。

when I enter a Smarty page, if the page do not exists a access_token variable, I want the modal popup automatically. 当我进入一个Smarty页面时,如果该页面不存在access_token变量,我希望自动弹出模式对话框。

So, how to realize in this example? 那么,在这个例子中如何实现?

  1. With JavaScript (jQuery), select the modal element and store it in variable. 使用JavaScript(jQuery),选择模式元素并将其存储在变量中。
  2. Trigger the show method. 触发show方法。

     var myModal = $("#myModal"); myModal.modal("show"); 

To show a modal: $('#myModal').modal('show'); 显示模态:$('#myModal')。modal('show');

To hide a modal: $('#myModal').modal('hide'); 隐藏模态:$('#myModal')。modal('hide');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM