惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Hacker News: Ask HN
Hacker News: Ask HN
Recent Commits to openclaw:main
Recent Commits to openclaw:main
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
C
Check Point Blog
S
Security Affairs
Hacker News - Newest:
Hacker News - Newest: "LLM"
S
Secure Thoughts
Recorded Future
Recorded Future
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
T
The Blog of Author Tim Ferriss
B
Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Google DeepMind News
Google DeepMind News
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
A
Arctic Wolf
T
The Exploit Database - CXSecurity.com
Stack Overflow Blog
Stack Overflow Blog
T
Threat Research - Cisco Blogs
GbyAI
GbyAI
AWS News Blog
AWS News Blog
MongoDB | Blog
MongoDB | Blog
Y
Y Combinator Blog
Google Online Security Blog
Google Online Security Blog
T
Troy Hunt's Blog
I
InfoQ
L
LINUX DO - 热门话题
WordPress大学
WordPress大学
C
Cisco Blogs
G
GRAHAM CLULEY
The Register - Security
The Register - Security
A
About on SuperTechFans
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Schneier on Security
Schneier on Security
Project Zero
Project Zero
H
Hackread – Cybersecurity News, Data Breaches, AI and More
P
Privacy & Cybersecurity Law Blog
Cloudbric
Cloudbric
H
Hacker News: Front Page
小众软件
小众软件
雷峰网
雷峰网
The Hacker News
The Hacker News
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Tor Project blog
博客园 - 聂微东
N
Netflix TechBlog - Medium
V
Vulnerabilities – Threatpost
The GitHub Blog
The GitHub Blog
腾讯CDC
P
Palo Alto Networks Blog
Scott Helme
Scott Helme

博客园 - goooto

Spring4.1新特性——Spring缓存框架增强(转) Spring整合Ehcache管理缓存(转) 《权力的游戏》第七季片场照曝光 MINA2 框架详解(转) Docker简明教程(转) IIS7.5 Gzip压缩配置 UML 依赖 关联 聚合 组合 亲属称谓 以字节流上传文件 C#命名规范(微软官方版) MongoDB学习笔记(六) MongoDB索引用法和效率分析(转) MongoDB学习笔记(五) MongoDB文件存取操作(转) MongoDB学习笔记(四) 用MongoDB的文档结构描述数据关系(转) MongoDB学习笔记(三) 在MVC模式下通过Jqgrid表格操作MongoDB数据(转) MongoDB学习笔记(二) 通过samus驱动实现基本数据操作(转) MongoDB学习笔记(一)MongoDB介绍及安装(转) Log4net配置相关 VS2010快捷键大全 WindowsService注册
JQuery中得到Element真实top、left、height和width属性值的对象 - goooto - 博客园
goooto · 2010-12-09 · via 博客园 - goooto

使用的JQuery1.3.2获得Element的实际的top、left、height和width时,对于IE浏览器和Chrome需要使用不同的代码来得到。为了便于统一使用,我 自己写了一个对象,在这里记录下来,以备将来参考。 
JQuery的版本为1.3.2 
该对象的代码如下: 

  1. var isIE = $.browser.msie;  
  2. function JQElement(){  
  3.     this.obj;  
  4.     this.top;  
  5.     this.left;  
  6.       
  7.     this.getE = function(objid) {  
  8.             this.obj = $("#" + objid);  
  9.             this.top = this.obj.offset().top;  
  10.             this.left = this.obj.offset().left;   
  11.         }  
  12.           
  13.         return this;  
  14.     }  
  15. }  

调用该对象的代码为: 

  1. var $searchdiv = new JQElement().getE("search_div");  
  2. var searchtop = $searchdiv.top;  
  3. var searchleft = $searchdiv.left;  
  4. delete $searchdiv;  

通过该对象的编写,在使用JQuery获得div元素的实际位置时,代码量减少了不少。同时对于JQuery在其他的浏览器出现可能的问题时,修改起来也会更加方便。