Passing data to a bootstrap modal

后端 未结 12 1780
心在旅途
心在旅途 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条回答
  •  眼角桃花
    2020-11-21 14:07

    Here is a cleaner way to do it if you are using Bootstrap 3.2.0.

    Link HTML

    Open Modal
    

    Modal JavaScript

    //triggered when modal is about to be shown
    $('#my_modal').on('show.bs.modal', function(e) {
    
        //get data-id attribute of the clicked element
        var bookId = $(e.relatedTarget).data('book-id');
    
        //populate the textbox
        $(e.currentTarget).find('input[name="bookId"]').val(bookId);
    });
    

    http://jsfiddle.net/k7FC2/

提交回复
热议问题