使用javascript onClick显示Bootstrap Modal

时间:2016-09-24 06:02:25

标签: javascript jquery bootstrap-modal

如何在点击时在javascipt中添加引导模式。到目前为止,我只能在点击时提醒("你好")。我如何提示出一个模态框?

 graph.on("click", function (params) {
       var node = params['nodes'][0];
       displayInfo=false;
       if(node!=null){
        console.log('node:'+ params['nodes'][0]);
         x = params["pointer"]['canvas']['x'];
         y = params["pointer"]['canvas']['y'];   

         displayInfo=true;
         lastNode = nodes.get(node);
         lastClick = params['pointer'];
         //console.log(node);   
       }
       alert("hello");

       //add boostrap modal here    
     });

4 个答案:

答案 0 :(得分:0)

你不需要onclick。

<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>

如果您无论如何都需要onclick事件,请使用如下所示:

    graph.on("click", function (params) {
$('#myModal').modal('show');
}

参考:http://getbootstrap.com/javascript/#modals

答案 1 :(得分:0)

答案 2 :(得分:0)

您可以使用ID

$("#modal-id").modal("show");

或者您可以使用班级名称$(".modal-class").modal("show");

答案 3 :(得分:0)

首先让模态弹出div然后,配置并使用.modal(&#39; show&#39;) 例如: -

 <a href="" data-target="#modalDiv" data-toggle="modal"> You can also use onClick call for jquery here.  </a>
  <div id="modalDiv">
       //some content
  </div>

在jquery使用中,

     $("#modalDiv").modal('show');

选中此http://getbootstrap.com/javascript/#live-demo