<ul>
<li>aaaa</li> <br>
<li>bbbb</li> <br>
<li>cccc</li> <br>
<li>dddd</li> <br>
<li>eeee</li> <br>
<li>ffffffff</li> <br>
<li>gggg</li> <br>
</ul>
<script>
var obj = document.getElementsByTagName('li');
for (var i = 0; i < obj.length; i++) {
obj[i].id = i;
obj[i].onclick = function () {
console.log(this.id);
}
}
</script>