The .aclick
doesn't have an id
and data-link
, they will return undefined
, you need to find the image and get those from the image. To get the data-link
use ().data('link')
not data('data-link')
. To load the file in your modal you'll have to use AJAX or the .load()
to laod a file.
<script>
$(".aclick").click(function (e) {
e.preventDefault();
$image = $(this).find('img');
var id = $($image).attr('id');
var link = $($image).data("link");
console.log(id);
console.log(link);
$('#modal_'+id).modal('show');
// using AJAX to fetch the file
$.get(link, function (response) {
$('.modal-body').html(response);
})
});
</script>
Or use modal.load()
to load the file.
<script>
$(".aclick").click(function (e) {
e.preventDefault();
$image = $(this).find('img');
var id = $($image).attr('id');
var link = $($image).data("link");
console.log(id);
console.log(link);
// load the file
$('.modal-body').load(link, function () {
$('#modal_'+id).modal('show');
})
});
</script>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…