offset函数 代码:【复制】
function offset(e){
var t = e.offsetTop;
var l = e.offsetLeft;
var w = e.offsetWidth;
var h = e.offsetHeight - 2;
while(e = e.offsetParent){
t += e.offsetTop;
l += e.offsetLeft;
}
return {
top : t,
left : l,
width : w,
height : h
}
}
代码:【复制】
function AutoSizeDIV(objID){
var obj = document.getElementById(objID);
var obj_div = Offset(obj);
if (obj.scrollHeight < obj.offsetHeight){
obj.style.height = obj.scrollHeight + 2;
}
if (obj_div.height > 200){
obj.style.height = '200px';
obj.style.overflowX = 'hidden';
obj.style.overflowY = 'auto';
}
}