<html>
<title></title>
<head>
<script>
function loads(){
var elements=document.getElementsByTagName("div");
for(var i=0;i<elements.length;i++){
var eleObj=elements[i];
eleObj.onclick=doSomething(eleObj.innerHTML);//传递参数
}
}
function doSomething(content){ //返回一个匿名函数
return (
function(){
alert(content);
//
}
)
}
</script>
</head>
<body onload="loads();">
<div id="1" width="50px" height="50px">div1</div>
<div id="2" width="50px" height="50px">div2</div>
<div id="3" width="50px" height="50px">div3</div>
<div id="4" width="50px" height="50px">div4</div>
</body>
</html>