2

我正在尝试在页面加载时出现一个 twitter-bootstrap 模式对话框以获取某个视图。我正在使用代码执行此操作:

<script>
$(window).load(function(){
        $('#shareModal').modal('show');
    });
</script>

<div class="modal hide fade" id="shareModal">
  <div class="modal-header">
    <a class="close" data-dismiss="modal">×</a>
    <h3>Modal header</h3>
  </div>
  <div class="modal-body">
    <p>One fine body…&lt;/p>
  </div>
  <div class="modal-footer">
    <a href="#" class="btn">Close</a>
    <a href="#" class="btn btn-primary">Save changes</a>
  </div>
</div>

在页面加载时,不是弹出模式,而是屏幕显示为“灰色”(褪色)并且什么也没有出现。有人知道会发生什么吗?谢谢你。

4

2 回答 2

1
<!-- Modal -->
<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">Modal title</h4>
      </div>
      <div class="modal-body">
        One fine 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><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

JS

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

演示

于 2013-12-02T16:12:49.997 回答
1

嗯,我认为你应该用 Bootstrap 3 试试这个:

<div class = "modal fade" id="shareModal" role = "dialog">
    <div class = "modal-dialog">
        <div class = "modal-content">
            <div class="modal-header">
                <a class="close" data-dismiss="modal">×</a>
                <h3>Modal header</h3>
            </div>
            <div class="modal-body">
                <p>One fine body…&lt;/p>
            </div>
            <div class="modal-footer">
                <a href="#" class="btn">Close</a>
                <a href="#" class="btn btn-primary">Save changes</a>
            </div>
        </div>
    </div>
</div>

在浏览器的控制台中输入: $('#shareModal').modal(); 测试你的模态

于 2013-12-02T15:30:06.713 回答