简体   繁体   中英

I want to use a div as a twitter bootstrap modal link

Can help me? I want to use a div as a twitter bootstrap modal link. when i will click on a div it will call a modal. is it possible? if possible then please show me a way. I think it is possible but i dont know how to do this. please help me.

Use $modal.modal('show'); in your onclick event handler.

HTML:

<div class="my-div"></div>

<div class="modal hide fade">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h3>Modal header</h3>
  </div>
  <div class="modal-body">
    <p>One fine body…</p>
  </div>
  <div class="modal-footer">
    <a href="#" class="btn">Close</a>
    <a href="#" class="btn btn-primary">Save changes</a>
  </div>
</div>

JavaScript:

var $modal = $('.modal').modal({
    show: false
});
$('.my-div').on('click', function() {
    $modal.modal('show');
});

DEMO

Here is a demo link .

Your HTML:

<div data-toggle="modal" href="#example">Launch modal</div>

<div id="example" class="modal hide fade in" style="display: none;">
    <div class="modal-header">
        <a class="close" data-dismiss="modal">×</a>
        <h3>This is a Modal Heading</h3>
    </div>
    <div class="modal-body">
        <h4>Text in a modal</h4>
        <p>You can add some text here.</p>              
    </div>
    <div class="modal-footer">
        <a href="#" class="btn btn-success">Call to action</a>
        <a href="#" class="btn" data-dismiss="modal">Close</a>
    </div>
</div>

Your JS (assumes you are already including the needed bootstrap files, both JS and CSS):

$(function () { 
   $("#example").modal({show:false});  
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM