code Javascript:
var multiArray;
window.onload = function() {
// load the table into the multidimensional array.
multiArray = [];
var trs = document.getElementsByTagName('TR');
for(var i = 0; i < trs.length; i++) {
var arr = [];
var tds = trs[i].childNodes;
for(var j = 0; j < tds.length; j++) {
var td = tds[j];
if (td.tagName === 'TD') {
arr.push(td.innerHTML);
}
}
multiArray.push(arr);
}
// perform some calculations between the columns of the array
var resCalc = [];
for(i = 0; i < multiArray.length; i++) {
resCalc[i] = 0;
for(j = 0; j < multiArray[i].length; j++) {
resCalc[i] += multiArray[i][j];
}
}
// insert the results into a column of the same array
var columnToModify = 0; // the index of the column you want to change
for(i = 0; i < multiArray.length; i++) {
multiArray[i][columnToModify] = resCalc[i];
}
};
Parlez-vous de l'ajout de deux tableaux? Comme dans 'c [i] = a [i] + b [i];'? –
Je ne peux pas faire assez de sens de cette question pour l'éditer en quelque chose de plus compréhensible ... avez-vous utilisé un traducteur pour cela? Bien sûr, ce n'est pas un problème, mais ce pourrait être une bonne idée de recommencer. –
multimencional, vouliez-vous dire multidimensionnel? Comment insérer des valeurs d'une table html dans un tableau multidimensionnel en javascript? –