我正在尝试制作一个这样的通知框:
如您所见,有一张图片 .gif
在它的顶部,当内容加载时将被隐藏。现在我想将以下图像添加到 <div>
:
这是我的 ajax 代码:
function notification(){
$(".notifications_list").html(/* add this path: /myfolder/img/progress.gif */ );
$.ajax({
url : '/myweb/files/notification.php',
dataType : 'JSON',
success : function (notification_system) {
$(".notifications_list").html(/* remove progress.gif photo */ );
if(notification_system.success === 1){
$(".notifications_list").html(notification_system.notifications);
} else {
alert('something is wrong');
}
}
});
}
请关注这两行:
$(".notifications_list").html(/* add this path: /myfolder/img/progress.gif */ );
$(".notifications_list").html(/* remove progress.gif photo */ );
我该怎么做?我的意思是,如何通过图像的路径将图像添加到 HTML,然后将其删除?
最佳答案
尝试“添加”和“删除”...
$('.notifications_list').prepend('<img class="your_image" src="http://placekitten.com/100/100">')
并删除
$('.notifications_list .your_image').remove();
关于javascript - 如何通过 JS(或 jQuery)将图像设置为 div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39058578/