JS获取控件绝对位置
来源:互联网 发布:审批系统 数据库设计 编辑:程序博客网 时间:2024/06/05 17:48
<!DOCTYPE html><html><head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript"> // 输出控件位置 function printPoint(pElement){ alert("该按钮位置为:左"+getAbsoluteLeft(pElement.id)+"上"+getAbsoluteTop(pElement.id)); } //获取控件左绝对位置 function getAbsoluteLeft(pElementId) { o = document.getElementById(pElementId); oLeft = o.offsetLeft; while(o.offsetParent!=null) { oParent = o.offsetParent; oLeft += oParent.offsetLeft; o = oParent; } return oLeft; } //获取控件上绝对位置 function getAbsoluteTop(pElementId) { o = document.getElementById(pElementId); oTop = o.offsetTop; while(o.offsetParent!=null) { oParent = o.offsetParent ; oTop += oParent.offsetTop ; // 加父层级顶部位置 o = oParent ; } return oTop ; } </script></head><body><div style="text-align:center;margin:0 auto;border:1px solid #000;width:200px;height:200px"><br><input id="button1" type="button" style="width:125px;height:25px;" value = "查看该按钮位置" onclick="printPoint(this)" ></button><br><br><br><input id="button2" type="button" style="width:125px;height:25px;" value = "查看该按钮位置" onclick="printPoint(this)" ></button><br><br><br><input id="button3" type="button" style="width:125px;height:25px;" value = "查看该按钮位置" onclick="printPoint(this)" ></button><br></div></body></html>
阅读全文
0 0
- JS获取控件绝对位置
- Silverlight获取控件绝对位置
- 获取控件的绝对位置
- js获得控件绝对位置
- js获取控件位置
- js获取控件位置
- js获取控件位置
- js获取控件位置
- js获取控件位置
- 获取页面控件的绝对位置
- 获取控件在网页中的绝对位置
- 获取控件绝对位置,显示div
- jquery获取控件的绝对位置
- jquery获取控件的绝对位置
- 获取控件在网页中的绝对位置
- 获取控件在网页中的绝对位置
- JS中获取对象的绝对位置
- js获取滚动条位置:绝对有效
- java反射回顾<三>
- 原生断点续传
- MySQL GROUP_CONCAT函数
- 隔行变色以及选中高亮/变色
- C# 接口
- JS获取控件绝对位置
- 安卓开发常用工具和第三方库汇总
- myeclipse使用tomcat时报错“An internal error occurred during: "Launching……”
- 单例模式的七种写法
- 了解spring,struts源码路上的第一步
- 云中数据管理是谁的责任?不得不说的云中真相……
- 谷歌浏览器 VS 火狐量子:哪一个更快呢?
- “下里巴人”与“阳春白雪”,永洪科技展现“全企业”数据智能
- 【LeetCode】41. First Missing Positive(Hard)解题报告