<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>测试节点</title>
</head>
<body>
<div id="div2">
<div id="p3" class="hehe">div3</div>
<div id="p4">div4</div>
<div id="p5">div5</div>
</div>
<div id="div1">显示点击ID</div>
<script>
function elClick(object)
{
document.getElementById('div1').innerHTML=object.innerText;
}
function init(){
var p = document.getElementById("div2").children;
for(var iLoop = 0; iLoop < p.length; iLoop ++)
{
var tmp = p[iLoop];
console.log(tmp.nodeName);
if(tmp.nodeName == 'DIV')
{
tmp.onclick = function(){elClick(this)};
}
}
}
init();
</script>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>测试节点</title>
</head>
<body>
<div id="div2">
<div id="p3" class="hehe">div3</div>
<div id="p4">div4</div>
<div id="p5">div5</div>
</div>
<div id="div1">显示点击ID</div>
<script>
function elClick(object)
{
document.getElementById('div1').innerHTML=object.innerText;
}
function init(){
var p = document.getElementById("div2").children;
for(var iLoop = 0; iLoop < p.length; iLoop ++)
{
var tmp = p[iLoop];
console.log(tmp.nodeName);
if(tmp.nodeName == 'DIV')
{
tmp.onclick = function(){elClick(this)};
}
}
}
init();
</script>
</body>
</html>