<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<script>
var d=document.getElementsByTagName('div');
for(var i=0;i<d.length;i++){
(function(i){
d[i].onclick=function(){
alert(i);
}
})(i)
}
</script>
</body>
</html>
无聊玩闭包
最新推荐文章于 2021-06-28 21:37:34 发布