, ", ", , , ( , ), .
, ; , , .
function numberDiagonally(tableId) {
var rows = document.getElementById(tableId).rows,
numRows = rows.length,
numCols = rows[0].cells.length,
sq = numRows + numCols - 1,
d, x, y,
i = 1,
dc,
c = -1,
colors = ["green","yellow","orange","red"];
diagonalLoop:
for (d = 0; d < sq; d++) {
dc = "diagonal" + d;
for (y = d, x = 0; y >= 0; y--, x++) {
if (x === numCols)
continue diagonalLoop;
if (y < numRows)
$(rows[y].cells[x]).html(i++).addClass(dc);
}
}
for (d = 0; d < sq; d++)
$(".diagonal" + d).css("background-color", colors[c=(c+1)%colors.length]);
}
: http://jsfiddle.net/7NZt3/2
, , , , x y , - , . EDIT: , ? , , , ( , i, , ). , , , sq โโ , - , . .
, , . , , jQuery .
, , ...
UPDATE - , : http://jsfiddle.net/7NZt3/1/ ( , , ).