欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

元素未顯示設(shè)置width/height時IE中使用currentStyle獲取為auto

 更新時間:2014年05月04日 09:35:19   作者:  
元素未顯示設(shè)置width/height時IE中無法使用currentStyle獲取,默認(rèn)獲取值為auto,需要的朋友可以參考下
我們知道獲取元素的實際寬高在IE中可以使用currentStyle屬性。但如果沒有顯示的去設(shè)置元素的寬高,那么使用該屬性將獲取不到,獲取的值為auto。如下
復(fù)制代碼 代碼如下:

<div>abcd</div>
<script>
var div = document.getElementsByTagName('div')[0];
alert(div.currentStyle.width);
alert(div.currentStyle.height);
</script>

IE6/7/8/9中輸出的都是auto。如果顯示的設(shè)置了寬高,那么輸出的就是實際寬高。如下

1,通過內(nèi)聯(lián)style屬性設(shè)置
復(fù)制代碼 代碼如下:

<div style="width:100px;height:50px;">abcd</div>
<script>
var div = document.getElementsByTagName('div')[0];
alert(div.currentStyle.width);
alert(div.currentStyle.height);
</script>

2,通過頁面嵌入style標(biāo)簽設(shè)置
復(fù)制代碼 代碼如下:

<style>
div {
width: 100px;
height: 50px;
}
</style>
<div>abcd</div>
<script>
var div = document.getElementsByTagName('div')[0];
alert(div.currentStyle.width);
alert(div.currentStyle.height);
</script>

都將輸出:100px,50px

相關(guān)文章

最新評論