您的位置:首页 > Web前端 > JavaScript

js闭包判断点击的元素顺序

2017-08-27 18:26 274 查看
<div class="box" style="background: red;">box</div>

<div class="box" style="background: blue;">box</div>

<div class="box" style="background: yellow;">box</div>

<div class="box" style="background: red;">box</div>

<div class="box" style="background: blue;">box</div>

<script>
function inter(i){
var onclick=function(e){
console.log(i);
}
return onclick;
}
var box = document.querySelectorAll('.box');
for(var i=0;i<box.length;i++){
box[i].onclick=inter(i);
}

</script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: