Modalbox中缺少标题

时间:2018-06-27 17:18:01

标签: html twitter-bootstrap

我在引导程序模式框中的标题有问题。我有不同的框,其中包含x个链接。每个链接都在打开自己的模态框,其中包含该链接的相关内容。

我用代码here

制成了一个JsFiddle

如果我单击“取消订单”,则会出现一个标题为“取消订单”的模式框。我需要该标题为“取消订单”。对我来说,标题似乎在使用data-whateverid

如何在每个模式框中设置标题?

HTML

<div class="row">
  <div class="col-md-3">
    <div class="panel panel-primary">
      <div class="panel-heading">
        <h3 class="panel-title">GENERAL</h3>
      </div>
      <div class="panel-body">
        <a href="#" data-toggle="modal" data-target="#contactPageModal" data-whatever="cancel-order">Cancel order</a><br/>
        <a href="#" data-toggle="modal" data-target="#contactPageModal" data-whatever="change-order">Change order</a><br/>
        <a href="#" data-toggle="modal" data-target="#contactPageModal" data-whatever="test">Headline test</a><br/>
        <div class="modal fade" id="contactPageModal" tabindex="-1" role="dialog" aria-labelledby="contactPageModalLabel">
          <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="contactPageModalLabel">Cancel order</h4>
              </div>
              <div class="modal-body" id="cancel-order">A text about canceling an order
                <div class="modal fade bs-contact-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
                  <div class="modal-dialog modal-lg" role="document">
                    <div class="modal-content">

                    </div>
                  </div>
                </div>
              </div>
              <div class="modal-body" id="change-order">A text about changing your order
                <div class="modal fade bs-contact-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
                  <div class="modal-dialog modal-lg" role="document">
                    <div class="modal-content">

                    </div>
                  </div>
                </div>
              </div>
              <div class="modal-body" id="test">Test text
                <div class="modal fade bs-contact-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
                  <div class="modal-dialog modal-lg" role="document">
                    <div class="modal-content">

                    </div>
                  </div>
                </div>
              </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

Javascipt:

$('#contactPageModal').on('show.bs.modal', function(event) {
      var button = $(event.relatedTarget) 
      var recipient = button.data('whatever') 
      var modal = $(this)
      modal.find('.modal-title').text(' ' + recipient)
      modal.find('.modal-content .modal-body').hide();
      modal.find('.modal-content #' + recipient).show();
    })

1 个答案:

答案 0 :(得分:0)

 <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>
  <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal2">Open Modal 2</button>

  <!-- Modal -->
  <div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">

      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Modal Header</h4>
        </div>
        <div class="modal-body">
          <p>Some text in the modal.</p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>
    </div>
  </div>

  <div class="modal fade" id="myModal2" role="dialog">
    <div class="modal-dialog">

      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Modal Header 2</h4>
        </div>
        <div class="modal-body">
          <p>Some text in the modal 2.</p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>
    </div>
  </div>

</div>