parentNode、parentElement,childNodes、children 它们有什么区别呢?

winder 2006-09-22 02:02:17
parentNode、parentElement,childNodes、children 它们有什么区别呢?
...全文
402 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
fosjos 2006-09-22
  • 打赏
  • 举报
回复
我也从dhtml手册里拿了两段^_^
parentElement children:
There is no public standard that applies to this property/collection.
parentNode childNodes:
This property/collection is defined in World Wide Web Consortium (W3C) Document Object Model (DOM) Level 1 .

很多W3C标准从IE5才开始支持
IE4以前的只能用ie自己的方法
是W3C太晚,还是microsoft问题,哪位牛人有空解答一下吧
lantersen 2006-09-22
  • 打赏
  • 举报
回复
以下是简单的解释,注意个别字的差异:
parentNode Property: Retrieves the parent object in the document hierarchy.

parentElement Property:Retrieves the parent object in the object hierarchy.

childNodes:
Retrieves a collection of HTML Elements and TextNode objects that are direct descendants of the specified object.

children:
Retrieves a collection of DHTML Objects that are direct descendants of the object.





winder 2006-09-22
  • 打赏
  • 举报
回复
也就是说parentElement、children是IE自家的东西,别的地方是不认的。
那么,他们的标准版就是parentNode,childNodes。
这两个的作用和parentElement、children是一样的,并且是标准的、通用的。
fosjos 2006-09-22
  • 打赏
  • 举报
回复
这个不是“标准不一样”,
另外两个根本就不是标准,
可以理解为ie自定义的
winder 2006-09-22
  • 打赏
  • 举报
回复
只是标准不一样吗?
liufei8463 2006-09-22
  • 打赏
  • 举报
回复
用这parentNode,childNodes 2个就行了.楼上的都是正解!
vampireRE 2006-09-22
  • 打赏
  • 举报
回复
parentNode和parentElement功能一样,childNodes和children功能一样。但是parentNode和childNodes是符合W3C标准的,可以说比较通用。而另外两个只是IE支持,不是标准,Firefox就不支持
gzwuyh 2006-09-22
  • 打赏
  • 举报
回复
parentElement 获取对象层次中的父对象。
parentNode 获取文档层次中的父对象。
childNodes 获取作为指定对象直接后代的 HTML 元素和 TextNode 对象的集合。
children 获取作为对象直接后代的 DHTML 对象的集合。

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧