javascript - 如何通过 JS(或 jQuery)将图像设置为 div?

标签 javascript jquery html css

我正在尝试制作一个这样的通知框:

enter image description here

如您所见,有一张图片 .gif在它的顶部,当内容加载时将被隐藏。现在我想将以下图像添加到 <div> :

enter image description here

这是我的 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();

Demo here...

关于javascript - 如何通过 JS(或 jQuery)将图像设置为 div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39058578/

相关文章:

javascript - 导入组件自带的模块

jquery - 将焦点集中到 jQueryUI 对话框中的第一个表单元素

javascript - 如何使用 jQuery 在数据属性中添加文本?

javascript - 是否可以使用 EM 在媒体查询中覆盖浏览器的默认字体大小?

javascript - jquery 焦点没有第二次触发

javascript - 从数组和对象数组中提取对象的属性作为数组

javascript - 从 3xx : Redirection HTTP response with Web Extension 获取重定向位置 (URL)

PHP、Javascript、HTML

javascript - 第二次访问用户后用 cookie 隐藏 div

Javascript/jquery : Remove parent of class and keep it's child