简体   繁体   中英

call bootstrap modal dialog through script function

In my html page, now I open modal dialog in this way

Modal Call button

<a class="btn btn-primary btn-xs" data-toggle="modal" data-target="#editBox" href="file.php?id=<?php echo $obj->id;?>">

The following html code in page

<div class="modal fade" id="editBox" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
          //Content Will show Here
        </div>
    </div>
</div>

And this is file.php

<?php
$Id = $_GET["id"];
?>
<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal">&times;</button>
    <h4 class="modal-title"><center>Heading</center></h4>
</div>
<div class="modal-body">
    //Show records fetched from database against $Id
</div>
<div class="modal-footer">
    <button type="button" class="btn btn-default">Submit</button>
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>

What if I need to call the modal through script function ?

I have this

eventClick: function (result) {

   // call the dialog passing $id
})

EDIT

I need to pass $id value

Now I call the dialog with

href="file.php?id=<?php echo $obj->id;?>"

You can specify the url to load when opening the modal with the remote option:

$('#editBox').modal({
    remote: url + "?id=" + id, 
    show: true
});

The current recommendation is to use ajax to load the content rather than use the remote: option - this will be removed in later versions of bootstrap.

Source: http://getbootstrap.com/javascript/#via-javascript

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