用闭包的写法弹出元素的索引值

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="description" content="">
<meta name="keywords" content="">
<title>用闭包的写法弹出元素的索引值</title>
<!-- <script type="text/javascript" src="jquery-1.10.1.min.js"></script> -->
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
</head>
<script type="text/javascript">
// jquery写法;
// $(function() {
// $('li').click(function(event) {
// alert($(this).index());
// });
// });


// js原生写法一;
// window.onload=function(){
// var aLi=document.getElementsByTagName('li');
// for (var i=0;i<aLi.length;i++) {
// var aa=function(i){
// aLi[i].onclick=function(){
// // console.log(i);
// alert(i);
// };
// };
// aa(i);
// }
// }

// js原生写法二闭包;
window.onload=function(){
var aLi=document.getElementsByTagName('li');
for (var i=0;i<aLi.length;i++) {
(function(i){
aLi[i].onclick=function(){
// console.log(i);
alert(i);

};
})(i);
}
}

</script>
<body>
<ul>
<li>1111</li>
<li>1111</li>
<li>1111</li>
</ul>
</body>
</html>