使用javascript

时间:2018-01-12 15:18:44

标签: javascript bootstrap-modal

我想在javascript中显示基于bool变量的模态对话框。最好的方法是将bool变量绑定到某个属性(例如,可见性),当变量为true时,会出现模态对话框,如果为false,则会被忽略(" background"将显示网站)。 / p>

我使用this bootstrapious模板和jquery 1.9.1以及bootstrap 3.3.7。我在互联网上找到了一些相关主题,我尝试使用它们:

1)起初我使用了模态对话框div的一些属性,比如可见性,我将使用输出true或false的代码。我的意思是使用style="visibility:hidden" / visible,但是当它设置为可见时,它并不会自动显示。

2)使用来自getbootstrap.com的提示:$('#myModal').modal('show')以及出现onload或文档就绪的其他变体

$(document).ready(function(){
   jQuery.noConflict();
   $('#myModal').modal('show');
});

    $(document).on('load',function(){
        $('.modal').modal('show');
});

没有任何作品。

最后我会使用像

这样的东西
if(myVar == true)
     modal.show()
else
     modal.hide()

甚至有可能意识到这一点? 任何帮助表示赞赏!

1 个答案:

答案 0 :(得分:-1)

试试这个!

HTML

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
        ...
      </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>

和javascript

jQuery(document).ready(function(e) {
    jQuery('#myModal').modal();
});
相关问题