2010-10-19 50 views
0

我有以下代碼:CSS問題公開程度

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

JavaScript有一個try catch子句,如果你想發現錯誤 – 2010-10-19 13:37:14

+0

能見度「可見「。你不需要設置它。按F-12並打開調試器並檢查DOM中的該元素。 – 2010-10-19 13:39:16

+0

這是張貼在我們可以看的地方嗎? – Brad 2010-10-19 13:41:10

回答

4

語法錯誤。

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

應該

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

是的,謝謝,但它只適用於我設置zIndex屬性! – xdevel2000 2010-10-19 13:49:24

+0

然後,問題必須在其他地方,並在原來的職位以外的JavaScript。 – nnevala 2010-10-19 14:00:25

1

糾正這一行:

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

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