How to pass a parameter from a link element to a modal window?

后端 未结 3 1398
感情败类
感情败类 2020-12-21 13:54

I have a table. In a cell of the table there is a link like this:

相关标签:
3条回答
  • 2020-12-21 14:05
    //Global Variable
    value = '';
    
    $('[href = #remoteModal]').click(function(event){
            event.preventDefault();
            value = $(this).data("id");
            $('#remoteModal').show();
    });
    

    And I think you can access to value variable everywhere in this page

    0 讨论(0)
  • 2020-12-21 14:10
    var data-id = $(this).attr('data-id');
    

    So here in data-id you wll get your "XYZ"

    0 讨论(0)
  • 2020-12-21 14:12

    Use the .relatedTarget property mentioned in the Modal Event docs:

    $(document).ready(function () {
        $('#remoteModal').on('show.bs.modal', function (event) {
            console.log($(event.relatedTarget).attr('data-id'));
        });
    });
    
    0 讨论(0)
提交回复
热议问题