Twitter Bootstrap下拉列表,打开模态

时间:2015-02-25 13:56:08

标签: twitter-bootstrap drop-down-menu modal-dialog

尝试让一个下拉按钮打开,然后点击下拉列表中的项目时应打开一个模态 - 但不能正常工作,添加此代码:

<button type="button" class="btn btn-lg btn-warning dropdown-toggle" data-toggle="dropdown">By industries <span class="caret"></span>
                  </button> 
                  <ul class="dropdown-menu" role="menu">
                    <li><a href="#consumergoods">Consumer goods</a></li>

                    <div class="modal fade" id="consumergoods" data-target="#consumergoods">
                                          <div class="modal-dialog">
                                            <div class="modal-content">
                                              <div class="modal-header orange">
                                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                                <h4 class="modal-title"><strong></strong>Consumer goods</h4>
                                              </div>

可能做了一些严重的错误,但如果有人可以提供帮助,我会很高兴,谢谢!

1 个答案:

答案 0 :(得分:7)

您需要为.dropdownbutton设置一个包装器div <ul>,以便下拉列表正常工作,并且需要将属性data-toggle="modal"赋予的模式链路

<div class="dropdown">
    <button type="button" class="btn btn-lg btn-warning dropdown-toggle" data-toggle="dropdown">By industries <span class="caret"></span>    
    </button>
    <ul class="dropdown-menu" role="menu">
        <li><a href="#consumergoods" data-toggle="modal">Consumer goods</a></li>
    </ul>
</div>
<div class="modal fade" id="consumergoods" data-target="#consumergoods">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header orange">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>    
                </button>
                 <h4 class="modal-title"><strong></strong>Consumer goods</h4>    
            </div>
        </div>
    </div>
</div>

Fiddle