Passing data to a bootstrap modal

后端 未结 12 1925
心在旅途
心在旅途 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 13:47

    I think you can make this work using jQuery's .on event handler.

    Here's a fiddle you can test; just make sure to expand the HTML frame in the fiddle as much as possible so you can view the modal.

    http://jsfiddle.net/Au9tc/605/

    HTML

    Link 1

    test

     

    Link 2

    test

    JAVASCRIPT

    $(document).on("click", ".open-AddBookDialog", function () {
         var myBookId = $(this).data('id');
         $(".modal-body #bookId").val( myBookId );
         // As pointed out in comments, 
         // it is unnecessary to have to manually call the modal.
         // $('#addBookDialog').modal('show');
    });
    

提交回复
热议问题