.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);
            
没有报错;能够创造出节点;但是图片无法宣示;请问问题在哪里

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

阅读 4.1k
2 个回答

imgObj.setAttribute("background-image","url(imgs/images/7.png)")这么写有问题啊

imgObj.style.backgroundImage="url(imgs/images/7.png)"

你试试在后面加上,不要填充,定位之类的,都试试

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题