Javascript如何取得和設定div的高度和寬度,並且相容於任何瀏覽器?看程式碼:
http://www.itdos.com
http:/ /www.itdos.com
獲取div1的寬高度:
alert(document.getElementById("div1").offsetHeight); //相容FF、IE等
alert(document.getElementById("div1").offsetWidth) ; //兼容FF、IE等
設置div1的寬高度為div2的寬高度:
document.getElementById("div1").style.height=document.getElementById("div2").offsetHeight; //僅IE
document.getElementById2").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等