// костыль №1
document.getElementById('button-' + i).onclick = function(event) {
alert("This is button: " + event.target.id.split('-')[1]);
}
// костыль №2
document.getElementById('button-' + i).onclick = (function(i) {
return function() {
alert("This is button: " + i);
}
})(i)