我有以下代码:
var d = document.createElement("div");
d.id = "d_1";
d.style.backgroundImage = "url(img/lr.png");
d.style.backgroundRepeat = "no-repeat";
d.style.width = "150px";
d.style.height = "25px";
d.style.position = "absolute";
d.style.left = "460px";
d.style.top = "385px";
d.style.visibility = "visible";
document.documentElement.appendChild(d);
并且该div不会显示在Opera和Chrome中,但它会在firefox中显示!
怎么了?
答案 0 :(得分:4)
语法错误。
d.style.backgroundImage = "url(img/lr.png");
应该是
d.style.backgroundImage = "url(img/lr.png)";
答案 1 :(得分:1)
纠正这一行:
d.style.backgroundImage = "url(img/lr.png");
到
d.style.backgroundImage = "url(img/lr.png)";