.setAttribute()添加背景图片为何无法宣示

var imgObj=document.createElement("div");

        imgObj.style.backgroundImage="url(imgs/images/7.png)"
            console.log(imgObj)
            imgObj.setAttribute("style","position:absolute;left:"+left+"px;top:"+top+"px; background-repeat: 
            no-repeat;background-position: center; background-size: cover; height:35px; width:35px;border-radius: 100%;");
            $(".scan-gold-pic").append(imgObj);
            
没有报错;能够创造出节点;但是图片无法宣示;请问问题在哪里

我在调试的时候发现没有添加图片

https://img.mukewang.com/5bdbf9c30001c30402430166.jpg

扬帆大鱼
浏览 1096回答 1
1回答

www说

imgObj.setAttribute("background-image","url(imgs/images/7.png)")这么写有问题啊imgObj.style.backgroundImage="url(imgs/images/7.png)"
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript