Javascript CSS的可视性问题

Javascript CSS的可视性问题,javascript,css,cross-browser,Javascript,Css,Cross Browser,我有以下代码: 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";

我有以下代码:

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显示的

怎么了?

语法错误

d.style.backgroundImage = "url(img/lr.png");
应该是

d.style.backgroundImage = "url(img/lr.png)";
语法错误

d.style.backgroundImage = "url(img/lr.png");
应该是

d.style.backgroundImage = "url(img/lr.png)";
更正此行:

d.style.backgroundImage = "url(img/lr.png");

更正此行:

d.style.backgroundImage = "url(img/lr.png");


如果要检测错误,Javascript有一个try-catch子句。默认情况下,可见性为“可见”。你不需要设置它。按F-12并打开调试器并检查DOM中的元素。这是否发布在我们可以查看的地方?此外,document.documentElement返回文档根(即),在其中附加子元素有点可疑。我宁愿将新元素附加到document.bodyJavascript中,如果您想检测错误,那么它有一个try-catch子句。默认情况下,可见性为“可见”。你不需要设置它。按F-12并打开调试器并检查DOM中的元素。这是否发布在我们可以查看的地方?此外,document.documentElement返回文档根(即),在其中附加子元素有点可疑。我宁愿将新元素附加到document.body中,那么问题一定在其他地方,并且超出了原始帖子中的javascript。那么问题一定在其他地方,并且超出了原始帖子中的javascript。