当前位置:首页 > 设计在线 > 平面动画 > Photoshop > JS获取网页中HTML元素的几种方法分析

JS获取网页中HTML元素的几种方法分析

点击次数:25 次 发布日期:2008-11-21 11:44:34 作者:源代码网
源代码网推荐

源代码网整理以下  getElementById getElementsByName getElementsByTagName 大概介绍

源代码网整理以下  getElementById ,getElementsByName ,getElementsByTagName

源代码网整理以下  后两个是得到集合,byid只是得到单个对象

源代码网整理以下  getElementById 的用法

源代码网整理以下  举个例子:

源代码网整理以下  <a id="link1" name="link1" href=http://homepage.yesky.com>网页陶吧</a>

源代码网整理以下  同一页面内的引用方法:

源代码网整理以下  1、使用id:

源代码网整理以下  link1.href,返回值为http://homepage.yesky.com

源代码网整理以下  2、使用name:

源代码网整理以下  document.all.link1.href,返回值为http://homepage.yesky.com

源代码网整理以下  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:

源代码网整理以下  document.getElementById("link1").href

源代码网供稿.
网友评论 (0)
会员中心
设计在线
本站推荐
设计在线之精华