2011-11-27 16 views
0

在所有其他瀏覽器中,element.style似乎工作正常。 但Internet Explorer 8中不知道它...如何在Internet Explorer中設置內聯樣式?

收到此錯誤時,x是一個div:

Error: 'x.style.left' is null or not an object 

x.style本身是不確定的。我看着http://www.quirksmode.org/dom/changess.html,但它沒有提到特定元素上的風格,就像http://help.dottoro.com/ljuefnvw.php也沒有說任何東西。

+0

你可以告訴你實際使用的JS代碼? –

+0

元素之前有風格嗎? 'x.style' null? –

+0

是否分配了? – GolezTrol

回答

3
<div id="example"> 
    Test 
</div> 
<script> 
    document.getElementById('example').style.marginLeft = '50px'; 
</script> 

工作

+0

湯姆,你是對的。還有一些其他問題。在IE8中調試是可怕的:/。這是導致問題的確切線:parseInt(x [0] .style.left);其中x是實際dom元素的包裝。 – Blub

0

而不是使用element.style,請使用特定的標籤名稱。

+0

我覺得'element'存儲OP正在處理的元素。 – Blender

相關問題