Send parameter to Bootstrap modal window?

前端 未结 4 1851
北荒
北荒 2020-12-13 04:39

I have a problem, I cannot pass any parameters to a modal window (using Bootstrap 3), I tried using the solution stated in this link, but I cannot make it work:

Dyna

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-13 05:22

    First of all you should fix modal HTML structure. Now it's not correct, you don't need class .hide:

    
    

    Then links should point to this modal via data-target attribute:

    Edit 1
    

    Finally Js part becomes very simple:

        $('#edit-modal').on('show.bs.modal', function(e) {
    
            var $modal = $(this),
                esseyId = e.relatedTarget.id;
    
            $.ajax({
                cache: false,
                type: 'POST',
                url: 'backend.php',
                data: 'EID=' + essayId,
                success: function(data) {
                    $modal.find('.edit-content').html(data);
                }
            });
        })
    

    Demo: http://plnkr.co/edit/4XnLTZ557qMegqRmWVwU?p=preview

提交回复
热议问题