Voksin,
<html>
<head>
</head>
<body>
<script>
(function () {
var btn, t;
for (i=0; i < 24; i++) {
btn=document.createElement("BUTTON");
t=document.createTextNode("CLICK ME "+i);
btn.appendChild(t);
btn.onclick = (function(i){ return function() { alert(i); } })(i);
document.body.appendChild(btn);
}
})();
</script>
</body>
</html>