twitter bootstrap modal — how to pass data to callback function

前端 未结 3 1032
忘了有多久
忘了有多久 2021-01-26 05:18

is there a way to pass additional data to bootstrap modal function callback?

for example, lets say my link that causes the modal to open has an extra attribute in it wit

相关标签:
3条回答
  • 2021-01-26 05:39

    I know that this is an old question, but this is the first thing i've found on google. So, I want to put some important information here...

    You NEED to put your callback function binded on events BEFORE you call the modal, for example:

    $('#modal').on('shown', function(){ 
         // Do something when the modal is loaded
    });
    $("#modal").modal();
    

    This is very important and helped me a lot, so, here it is...

    0 讨论(0)
  • 2021-01-26 05:52

    Could this work for you ?

    <span listid="80" href="#editTaskList" data-toggle="datamodal" class="btn btn-mini right"><i class="icon-edit"></i> Edit Task List</span>
    
    var $editTaskList = $('#editTaskList');
    
    $('body').on('click.modal.data-api', '[data-toggle="datamodal"]', function (e) {
        var $this = $(this);
        $editTaskList.data('anyAttr',$this.data('anyAttr'));
        $editTaskList.modal('show');
        e.preventDefault();
    })
    
    $editTaskList.on('show', function () {
        var myData = $editTaskList.data('anyAttr');
    });
    
    0 讨论(0)
  • 2021-01-26 05:54

    Like this -

    <span id="modal_opener" data-extrastuff="stuff" listid="80" href="#editTaskList" data-toggle="modal" class="btn btn-mini right"><i class="icon-edit"></i> Edit Task List</span>
    
    $('#modal_opener').click(function() {
        var stuff_i_want = $(this).attr('data-extrastuff');
    });
    
    0 讨论(0)
提交回复
热议问题