pass var to bootstrap modal where php will use this value

前端 未结 2 784
無奈伤痛
無奈伤痛 2021-01-28 10:40

I have an undefined number of images on a page and I have 1 modal. I can open with these images this 1 modal, but I want to be able to know which image was clicked so I can use

2条回答
  •  耶瑟儿~
    2021-01-28 11:38

    wes,

    You an create a JS function and on click of each image get the src and pass it to the body of the modal.

    
    
    $('.setImage').click(function(event){
        event.preventDefault();
        var e = $(this);
        var title = 'set modal title here';
        var body = 'set modal body here';
        var modal = $('#exampleModal');
    
        modal.find('.modal-title').html(title);
        modal.find('.modal-body').html(body);
        modal.modal("show");
    });
    

提交回复
热议问题