<a href="#">0</a><br />
<a href="#">1</a><br />
<a href="#">2</a><br />
<a href="#">3</a><br />
<script>
elems = document.getElementsByTagName('a');
for(i=0;i<=elems.length;i++) {
elems[i].setAttribute('onclick', 'alert('+i+');return false;');
}
</script>