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

javascript獲取設(shè)置div的高度和寬度兼容任何瀏覽器

 更新時間:2013年09月22日 16:36:04   作者:  
Javascript如何獲取和設(shè)置div的高度和寬度,并且兼容任何瀏覽器,感興趣的朋友不妨看看下面的代碼或許有意想不到的收獲
Javascript如何獲取和設(shè)置div的高度和寬度,并且兼容任何瀏覽器?看代碼:
復(fù)制代碼 代碼如下:

<div id="div1" style="height:300px;width:200px;">http://www.itdos.com</div>
<div id="div2" style="height:30px;width:20px;">http://www.itdos.com</div>

獲取div1的寬高度:
復(fù)制代碼 代碼如下:

alert(document.getElementById("div1").offsetHeight); //兼容FF、IE等
alert(document.getElementById("div1").offsetWidth); //兼容FF、IE等

設(shè)置div1的寬高度為div2的寬高度:
復(fù)制代碼 代碼如下:

document.getElementById("div1").style.height=document.getElementById("div2").offsetHeight; //僅IE
document.getElementById("div1").style.height=document.getElementById("div2").offsetHeight+ "px"; //兼容FF、IE等
document.getElementById("div1").style.width=document.getElementById("div2").offsetWidth; //僅IE
document.getElementById("div1").style.width=document.getElementById("div2").offsetWidth+ "px"; //兼容FF、IE等

相關(guān)文章

最新評論