twitter-bootstrap 使用 Twitter Bootstrap 在一页内打开多个模态对话框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18941594/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 18:30:44  来源:igfitidea点击:

Open multiple modal dialogs inside one page with Twitter Bootstrap

asp.net-mvc-4twitter-bootstraptwitter-bootstrap-3

提问by IamStalker

I want to open multiple dialogs using Twitter Bootstrap 3.

我想使用Twitter Bootstrap 3打开多个对话框。

How can I do it? Can it be done at all?

我该怎么做?完全可以做到吗?

采纳答案by devo

First create some modals which you want like this.

首先创建一些你想要的模态。

<!-- 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">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><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
  </div><!-- /.modal -->

Then from your dynamic link switch to your modal using id to link href. Otherwise use onclick javascript event.

然后从您的动态链接切换到使用 id 链接 href 的模式。否则使用 onclick javascript 事件。

<a data-toggle="modal" href="#myModal" class="btn btn-primary btn-lg">Launch demo modal</a>

Or (the following option is better for you)

或者(以下选项更适合您)

<a href="javascript:void(null);" class="btn btn-primary btn-lg" onclick="launch_modal('your_id');">Launch Modal</a>

And from javascript,

从 javascript 中,

<script>
  function launch_modal(id) {
     // Hide all modals using class if required.
     $('.modal').modal('hide');
     $('#'+id).modal('show');
  }
</script>

回答by Undefined Behavior

another way is to have onethis html:

另一种方法是拥有一个这样的 html:

<div class="modal fade" id="modal" 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" title="Close">&times;</button>
            <h4 class="modal-title"></h4>
          </div>
          <div class="modal-body">
          </div>
          <div class="modal-footer">
          </div>
        </div><!-- /.modal-content -->
      </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->

And manyjquery like this to add content:

还有很多像这样添加内容的jquery:

$('#modal .modal-header .modal-title').html('<strong>:)</strong> Success!');
$('#modal .modal-body').html('<p>Something success!.</p>');
$('#modal .modal-footer').html('<button type="button" class="btn btn-default" data-dismiss="modal" title="Close">Close</button>');
$('#modal').modal('show');