仅使用javascript在IE浏览器中更改元素的宽度

时间:2011-08-11 09:41:18

标签: javascript

我希望仅在IE浏览器中使用javascript更改元素的宽度,但不知道如何执行此操作。

请尽快帮助我。

2 个答案:

答案 0 :(得分:1)

<!--[if IE]>
    <script type="text/javascript">
        document.getElementById('elementsId').style.width = '250px';
    </script>
<![endif]-->

答案 1 :(得分:0)

使用条件评论,或使用javascript检测浏览器。然后使用document.getElementById('id')检索元素,并更改其宽度。

例如:

document.onload = function()
{
 if(navigator.appName == 'Microsoft Internet Explorer')
 {
   document.getElementById('someElement').style.width = '200px';
 }
}

<div id='someElement' style='width:10px'>Some element</div>