How to pass id from button to modal

前端 未结 2 1260
陌清茗
陌清茗 2021-01-27 09:08

Reply Query

2条回答
  •  没有蜡笔的小新
    2021-01-27 09:35

    Will suggest more easy and less complicated approach and bootstrap framework will handle the rest.

    replace following

    
        
        
    
    

    With

    
        
    
    

    Use data-toggle and data-target attributes to open the modal and with additional data-id attribute and show.bs.modal or shown.bs.modal modal events, can pass the value to modal

    $(document).ready(function() {
      $('#modal-6').on('show.bs.modal', function(e) {
        var id = $(e.relatedTarget).data('id');
        alert(id);
      });
    });
    

    To keep the backdrop: 'static' add it in Modal HTML Markup

    
    

提交回复
热议问题