DEMO: http://jsfiddle.net/abc123/nCwDz/1/
Your code appears to be working to me...changed alert to console.log please use Firefox or Chrome and then go to the console to see it working.
To prove your closures are right I have changed your code to be indented appropriately.
CODE:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function runMe(){
for(var x=0; x<5; x++){
var d=document.createElement("DIV");
d.innerHTML="test " + x;
d.tabIndex=x;
d.onfocus=function(y){
return function(){
console.log("focus: " + y);
}
}(x);
d.onblur=function(y){
return function(){
console.log("blur: " + y);
}
}(x);
document.body.appendChild(d);
}
}
</script>
</head>
<body onload="runMe()">
</body>
</html>