Passing data to a bootstrap modal

后端 未结 12 1781
心在旅途
心在旅途 2020-11-21 13:10

I\'ve got a couple of hyperlinks that each have an ID attached. When I click on this link, I want to open a modal ( http://twitter.github.com/bootstrap/javascript.html#modal

12条回答
  •  闹比i
    闹比i (楼主)
    2020-11-21 13:52

    This is so easy with jquery:

    If below is your anchor link:

    
    
    

    In the show event of your modal you can access to the anchor tag like below

    //triggered when modal is shown
    $('#modal_id').on('shown.bs.modal', function(event) {
    
        // The reference tag is your anchor tag here
        var reference_tag = $(event.relatedTarget); 
        var id = reference_tag.data('id')
        // ...
        // ...
    })
    
    
    

提交回复
热议问题