首 页   · 站长博客 · 用户注册 · 会员登陆  · 会员排行  ·最新主题  ·最近回复  精华区  版权声明  ·论坛管理
  当前登录身份:游客,请先登录。  笔名: 口令: 验证码:   
楼 主  index »  HTML/JS/CSS技术专区 » JavaScript获得页面对象方法总结梳理(Lownyom原创发布)  


  作者:一起PHP
  注册时间:2004-02-27
  主题/回复:247/1521
  积分:4649
  等级:★★★★★☆(十一级)
  称号:论坛圣人

  nqp@nqp.me
  4304410
  www.nqp.me

 

 发表:2008-03-27 09:51:50 阅读 3202 次 回复 3 次 得分2  |   字号 字色
JavaScript获得页面对象方法总结梳理(Lownyom原创发布)
本资料为lownyom原创,本站整理发布。

如果是frame的
parent.function
如果是open的
this.opener.function 

举个例子:
代码如下:
<a id="link1" name="link1" href="http://www.51js.com/">51js</a>


=============
同一页面内的引用方法:

1、使用id:

link1.href

2、使用name:

document.all.link1.href

3、使用sourseIndex:

document.all(4).href //注意,前面还有HTML、HEAD、TITLE和BODY,所以是4

4、使用链接集合:

document.anchors(0).href //全部的集合有all、anchors、applets、areas、attributes、behaviorUrns、bookmarks、boundElements、cells、childNodes、children、controlRange、elements、embeds、filters、forms、frames、images、imports、links、mimeTypes、options、plugins、rows、rules、scripts、styleSheets、tBodies、TextRectangle,请参考MSDN介绍。其实方法3和方法4是一样使用的集合,只是一个是all,可以包括页面所有标记,而anchors只包括链接。

5、getElementById:  根据ID 捕获集合

document.getElementById("link1").href

6、getElementsByName: 根据name捕获集合

document.getElementsByName("link1")[0].href //这也是一个集合,是所有name等于该方法所带参数的标记的集合

7、getElementsByTagName:根据标签捕获集合

document.getElementsByTagName("A")[0].href //这也是一个集合,是所有标记名称等于该方法所带参数的标记的集合

8、tags集合:

document.all.tags("A")[0].href //与方法7一样是按标记名称取得一个集合

除此之外,
event.scrElement可以获得触发时间的标记的引用;
document.elementFromPoint(x,y)可以获得x和y坐标处的元素的引用;
document.body.componentFromPoint(event.clientX,event.clientY)可以获得鼠标所在处元素的引用;

还可以通过元素的父子节点和兄弟节点关系来引用,

如nextSibling(当前节点的后一节点)、previousSibling(当前节点的前一节点)、

childNodes、children、firstChild、lastChild、parentElement等都是父子节点和兄弟节点的一些引用;还不仅限于此。

上面是同一页面内的常见引用方法,另外还涉及到不同页面中的

=============
对于分帧的页面,

可以使用

parent.frames("帧的name")、top.frames("帧的name")来引用不同的帧,后面的引用和同一页面内市相同的,多重的parent也是支持的。

例如:

parent.frames("frame1").document.all.link1
top.frames("frame1").document.all.link1

=============
对于window.open()开的窗口

可以使用

var newwin=window.open()然后使用newwin来引用新窗口,后面的引用和同一页面内是相同的;

新窗口可以使用window.opener来引用打开它的窗口,可以简写作opener,例如:
var newwin=window.open()

父窗口(这里是使用window.open()方法的窗口):
newwin.document.all.link1 //父窗口这句可引用新窗口中的对象

子窗口(window.open()方法打开的窗口):
opener.document.all.link1 //子窗口这句可引用父窗口的对象

多重opener也是支持的,例如:opener.opener.document.all.link1 
方法多种多样,有时候需要根据具体的情况而定,灵活运用才可以游刃有余。 
 
 1#楼  
 
  回复人:lc0633
  注册时间:2007-08-08
  主题/回复:1/8
  积分:427
  等级:★★☆(五级)
  称号:略有小成

   
 1#楼 发表于2008-05-05 13:25:34  评分:1 

回复给楼主(一起PHP)
 2#楼  
 
  回复人:yanwanrong
  注册时间:2009-10-20
  主题/回复:0/39
  积分:101
  等级:★☆(三级)
  称号:牛刀小试

   
 2#楼 发表于2009-10-20 14:52:17  评分:1 

回复给楼主(一起PHP)
Nexon Europe:Hello Nexonears!In order to facilitate payments for maple story mesos you all,another payment option has been added to NEXON Europe.Nexon Game Cards give you access to purchasable virtual items buy maple story mesos that can be used to enhance your gaming experience.They cheap maple story mesos can be found in the Sainsbury’s,Toys R Us and ASDA stores within the UK.For maple story mesos those who still have difficulties purchasing maple story mesos,we are constantly working to reach out to you.buy maple story mesos So stay tuned,and cheap maple story mesos we will give you good news!
 3#楼  
 
  回复人:yanwanrong
  注册时间:2009-10-20
  主题/回复:0/39
  积分:101
  等级:★☆(三级)
  称号:牛刀小试

   
 3#楼 发表于2009-10-20 14:53:27  评分: 

回复给楼主(一起PHP)
Nexon Europe:Hello Nexonears!In order to facilitate payments for maple story mesos you all,another payment option has been added to NEXON Europe.Nexon Game Cards give you access to purchasable virtual items buy maple story mesos that can be used to enhance your gaming experience.They cheap maple story mesos can be found in the Sainsbury’s,Toys R Us and ASDA stores within the UK.For maple story mesos those who still have difficulties purchasing maple story mesos, we are constantly working to reach out to you.buy maple story mesos So stay tuned,and cheap maple story mesos we will give you good news!
  页数1/1首页 « 1 » 末页
  发表回复:您还没有登陆,无法发表回复。请先[登陆]

一起PHP技术联盟 主办:一起PHP 联系方式:站长QQ:4304410 QQ群:8423742 20159565 站长博客 E-mail: nqp@nqp.me 执行时间:0.011sec
SimsmaBBS 2008 (v6.0) Developed by 17php.com,Copyright(C)2003-2010 All rights reserved. 副本授权:一起PHP官方专用版