nodeType 2属性节点是什么意思 怎么测不出来

快乐乔巴 2011-11-23 01:31:33
百度谷歌搜索了下 nodeType 2是属性节点 可是我用chrome测试 却怎么也出不来2
比如<a href="www.test.com"></a> 的href应该是属性节点吧 可是就是测不出来 这个属性节点到底是什么呢
...全文
221 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
峭沙 2011-11-28
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 chopper7278 的回复:]

引用 4 楼 axiheyhey 的回复:

<a id="link1" href="www.test.com"></a>
<script>
var a = document.getElemntById('link1');
var href = a.getAttributeNode('href');
alert(href.nodeType)
</script>

也就是说在ht……
[/Quote]对的,childNodes只包含元素节点和文本节点,不包含属性节点。
Legend1988 2011-11-25
  • 打赏
  • 举报
回复
其实这个基本没什么用,nodeType有用到的话都是1和3。
默默不得鱼 2011-11-25
  • 打赏
  • 举报
回复
XML结构里才有属性节点 html加载成xml attribute被解析成attributeNode
应该这样理解吧
快乐乔巴 2011-11-25
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 axiheyhey 的回复:]

<a id="link1" href="www.test.com"></a>
<script>
var a = document.getElemntById('link1');
var href = a.getAttributeNode('href');
alert(href.nodeType)
</script>
[/Quote]
也就是说在html中childNodes里遍历的节点 不可能会出现nodeType=2 先找到元素节点燃后getAttributeNode才可以找得到 是吗????
峭沙 2011-11-23
  • 打赏
  • 举报
回复
<a id="link1" href="www.test.com"></a>
<script>
var a = document.getElemntById('link1');
var href = a.getAttributeNode('href');
alert(href.nodeType)
</script>
hookee 2011-11-23
  • 打赏
  • 举报
回复

<script>
window.onload = function(){
var xml = new ActiveXObject("Msxml2.DOMDocument")
xml.loadXML("<a href=\"www.test.com\"></a>");
node = xml.selectSingleNode("//a/@href");
alert(node.nodeType); //2
}
</script>
快乐乔巴 2011-11-23
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 nihaox1 的回复:]

<div id="a"><a href="www.test.com"></a></div>

document.getElementById("a").childNodes[0].nodeType

试试
[/Quote]
明显是1啊 a节点类型啊 哪来的2啊
萧萧可乐 2011-11-23
  • 打赏
  • 举报
回复
<div id="a"><a href="www.test.com"></a></div>

document.getElementById("a").childNodes[0].nodeType

试试

87,902

社区成员

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

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