, , . tabIndex - , . jsfiddle.
Map, , . , tabIndex .
function setTabIndices() {
var tableIndex, rowIndex, colIndex, inputIndex;
var table, row, cell, inputs;
var map = new Map();
var tables = document.getElementsByTagName("table");
for (tableIndex = 0; tableIndex < tables.length; tableIndex++) {
table = tables[tableIndex];
for (rowIndex = 0; rowIndex < table.rows.length; rowIndex++) {
row = table.rows[rowIndex];
for (colIndex = 0; colIndex < row.cells.length; colIndex++) {
cell = row.cells[colIndex];
inputs = cell.getElementsByTagName("input");
for (inputIndex = 0; inputIndex < inputs.length; inputIndex++) {
map.set(format(tableIndex, 4) + format(colIndex, 6) +
format(rowIndex, 6) + format(inputIndex, 3),
inputs[inputIndex]);
}
}
}
}
var input;
var sortedKeys = [...map.keys()].sort();
for (var tabIndex = 1; tabIndex <= sortedKeys.length; tabIndex++) {
input = map.get(sortedKeys[tabIndex - 1]);
input.tabIndex = tabIndex;
}
}
function format(value, digits) {
return ("0000000000" + value.toString()).slice(-digits);
}
</" > . IE, :
var sortedKeys = [...map.keys()].sort();
If you must support IE, you can call map.forEachto populate an unsorted array, as shown in this modified jsfiddle .
source
share