使用javascript onClick显示Bootstrap模式
收藏

I need to be able to open a Twitter bootstrap modal window using the onClick="" or similar function. Just need the code to go into the onClick="". I am trying to make a click-able div to open the modal.

代码节选:

分区代码:

<div class="span4 proj-div" onClick="open('GSCCModal');">

模态Div代码:

<div id="GSCCModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

Javascript:

function open(x){
    $(x).modal('show');
}

最佳答案

您不需要onclick。假设您正在使用Bootstrap 3 Bootstrap 3文档

<div class="span4 proj-div" data-toggle="modal" data-target="#GSCCModal">Clickable content, graphics, whatever</div>

<div id="GSCCModal" class="modal fade" 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">
        ...
      </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>

如果您使用的是Bootstrap 2,请按照以下标记进行操作: http://getbootstrap.com/2.3.2/javascript.html#modals

    公众号
    关注公众号订阅更多技术干货!