黑马程序员技术交流社区
标题:
用dom列出HTML下所有元素的对象没反应,帮忙看看
[打印本页]
作者:
糖伯貓
时间:
2014-1-19 19:51
标题:
用dom列出HTML下所有元素的对象没反应,帮忙看看
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
function listAll(node)
{
var nodes = node.childNodes;
for(var x = 0; x<nodes.length ;x++)
{
if(nodes[x].hasChildNodes())
listAll(nodes[x]);
else
getInfo(nodes[x]);
}
}
function list()
{
listAll(document);
}
function getInfo (node) {
document.write("name:"+node.nodeName+"..type:"+node.nodeType+"..value:"+node.nodeValue);
}
</script>
</head>
<body>
<input type = "button" value = "按我" onclick="list()"></input>
<div id = "divid">
水电费;
</div>
<table id= "table">
<tr>
<td>第一个</td>
<td>第二个</td>
</tr>
<tr>
<td>第三个</td>
<td>第四个</td>
</tr>
</table>
<a >百度</a>
</body>
</html>
复制代码
作者:
HelloSummer
时间:
2014-1-19 21:01
<input type = "button" value = "按我" onclick="list()"></input>
复制代码
刚刚拿你那代码调试了下,这一句里面的onclick方法是无效的。原因不明。猜测可能是不同浏览器的兼容程度不同。我用的是chome。换成了下面这句就有反应了:
<button type="button" onClick="list();">按我</button>
复制代码
作者:
糖伯貓
时间:
2014-1-20 10:25
HelloSummer 发表于 2014-1-19 21:01
刚刚拿你那代码调试了下,这一句里面的onclick方法是无效的。原因不明。猜测可能是不同浏览器的兼容程度不同 ...
果然有效了 汗 谢了哦
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2