<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<ul id="test">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
<script type="text/javascript">
var oul = document.getElementById("test"),
oli = oul.getElementsByTagName("li");
for(var i = 0,j=oli.length;i<j;i++){
var index = i;
oli[i].onclick = (function(index){
return function(){
console.log(index);
}
})(index);
}
</script>
</body>
</html>