JS获得HTML元素位置
//获得元素位置function getAbsolutePosition(obj) { position = new Object(); position.x = 0; position.y = 0; position.h = 0; position.w = 0; var tempobj = obj; if (tempobj.offsetHeight + '' != 'undefined') { position.h = tempobj.offsetHeight; } if (tempobj.offsetWidth + '' != 'undefined') { position.w = tempobj.offsetWidth; } while (tempobj != null && tempobj != document.body) { position.x += tempobj.offsetLeft + tempobj.clientLeft; position.y += tempobj.offsetTop + tempobj.clientTop; tempobj = tempobj.offsetParent } return position; }//使用var ask = getAbsolutePosition(xxx);alert(ask.x); //横坐标alert(ask.y); //纵坐标alert(ask.h); //高alert(ask.w); //宽