提问人:chop bar 提问时间:8/11/2023 最后编辑:Sang Suantakchop bar 更新时间:8/11/2023 访问量:43
我想显示本地文件夹中的图像,但图像未显示
I want to display an image from a local folder yet images are not showing
问:
这是我想要显示图像的元素
<div id="policyFilesPreviewContainer"></div>
这是我的jQuery代码
var policyFilesPreview = $('<div>');
$.each(data[0].policy_files, function(policyId, policyFile) {
var policyRequirementDiv = $('<div>');
policyRequirementDiv.append('<h3>Policy Requirement ID: ' + policyFile.policy_requirement_id + '</h3>');
var filePreviewsContainer = $('<div>');
policyFile.file_names.forEach(function(fileName) {
// Create an <img> element for each image
var filePreview = $('<img>', {
src: 'assets/', // Replace with actual image path
alt: fileName
}).css({
width: '150px', // Adjust image width as needed
height: 'auto'
});
// Append the image to the container
filePreviewsContainer.append(filePreview);
});
// Append the container to the policy requirement div
policyRequirementDiv.append(filePreviewsContainer);
// Append the policy requirement div to the main preview container
policyFilesPreview.append(policyRequirementDiv);
});
// Clear and append the policyFilesPreview into the designated container
$('#policyFilesPreviewContainer').empty().append(policyFilesPreview);
尝试了很多方法,希望有人可以帮助我解决这个问题
答: 暂无答案
评论