Оно?
<!DOCTYPE html>
<html>
<head>
<!--
<script src="http://code.jquery.com/jquery-latest.js"></script>
<link rel="stylesheet" type="text/css" href="tmp.css" />
-->
<style type="text/css">
</style>
<script type="text/javascript">
window.onload=function() {
var o=document.getElementsByTagName("button")
for (var i=0; i<o.length;i++) {
o[i].onclick=(function (N) {
return function (){alert(N);}
})(i);
};
};
</script>
</head>
<body>
<button>0</button>
<button>1</button>
<button>2</button>
</body>
</html>