如何在Internet Explorer中设置内联样式?

时间:2011-11-27 19:37:40

标签: css internet-explorer

在所有其他浏览器中,element.style似乎工作正常。 但Internet Explorer 8并不知道......

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也没有说什么。

2 个答案:

答案 0 :(得分:3)

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

作品

答案 1 :(得分:0)

而不是使用element.style,请使用特定的标记名称。