function tab(col,lign) { this.tab = document.createElement("table"); this.autoid=1; for(j=0;j<lign;j++) { this.newRow = this.tab.insertRow(-1); for(i=0;i<col;i++) { this.newCell = this.newRow.insertCell(i); this.newCell.innerHTML = /* " "; */ this.autoid; this.newCell.setAttribute("id",this.autoid); with(this.newCell.style) { borderStyle = 'solid'; borderWidth = '2px'; borderColor = "#000000"; width = '100px'; height = '50px'; textAlign = 'center'; } this.autoid++; } } this.addtxt = function(id) { document.getElementById(id).innerHTML = "ne"; } document.body.appendChild(this.tab); }
Télécharger le zip
salut je viens de télécharger tas source , et elle ne fonctionne pas sous ff, sans doute a cause des fonctions insertRow et insertCell que je connais pas. Si tu veux utiliser un code utilisable par tout les navigateur utilise cette structure .var table = document.createElement("table");var tbody = document.createElement("tbody");var tr= document.createElement("tr");var td= document.createElement("td"); maSible.appendChild(table);table.appendChild(tbody);tbody.appendChild(tr);tr.appendChild(td);le tbody est obligatoire lorsqu on construit une tablepar le DOM ,bonne continuation
Comment faire un onclick sur vos Td dynamic?
Parce que this.newCell.onclick = "alert('test')";s'affiche bien, mais il n'y a pas d'alertj'ai essayé avec onClick, même résultat...
J'ai trouvé, il faut fairethis.newCell.onclick = new Function("alert('test')");
<html><head></head><body></body><script language='javascript'>function tab(col,lign,mep){ this.tab = document.createElement("table"); this.tab.setAttribute("align",mep); this.autoid=1; for(j=0;j<lign;j++) { this.newRow = this.tab.insertRow(-1); for(i=0;i<col;i++) { this.newCell = this.newRow.insertCell(i); this.newCell.innerHTML = /* " "; */ this.autoid; this.newCell.setAttribute("id",this.autoid); this.newCell.onclick = function () { window.alert(this.id); } with(this.newCell.style) { borderStyle = 'solid'; borderWidth = '2px'; borderColor = "#000000"; width = '100px'; height = '50px'; textAlign = 'center'; } this.autoid++; }} this.addtxt = function(id) { document.getElementById(id).innerHTML = "ne"; } document.body.appendChild(this.tab); }var tab = new tab(10,10,"center");</script></html>fonctionne sous firefox et sur IE
<html><head><style>div#lecture { border-style : solid; border-width : 2px; border-color : #000000; width : 100px; height :auto; text-align : center; }</style></head><body><div align='center'> <div id="lecture"></div></div></body><script language='javascript'>function tab(col,lign,mep){ this.tab = document.createElement("table"); this.tab.setAttribute("align",mep); this.autoid=1; this.lign = lign; for(j=0;j<lign;j++) { this.newRow = this.tab.insertRow(-1); for(i=0;i<col;i++) { this.newCell = this.newRow.insertCell(i); this.newCell.innerHTML = this.autoid; this.newCell.setAttribute("id",this.autoid); /* ############################# fonction de la cellule ################################### */ this.newCell.onclick = function () { window.alert(this.id); } this.newCell.onmouseover = function () { this.style.backgroundColor = "#FFF000"; document.getElementById("lecture").innerHTML = " "+ parseFloat(this.innerHTML*6.55957).toFixed(2)+" Francs "; } this.newCell.onmouseout = function () { this.style.backgroundColor = "#FFF"; } /* ############################# style de l'objet ################################### */ with(this.newCell.style) { borderStyle = 'solid'; borderWidth = '2px'; borderColor = "#000000"; width = '100px'; height = '50px'; textAlign = 'center'; } this.autoid++; }} /* ############################# fonction de l'objet ################################### */ this.addtxt = function(id) { document.getElementById(id).innerHTML = "ne"; } document.body.appendChild(this.tab); }var tab = new tab(10,10,"center");</script></html>produit customisé et dérivé pour ma grand-mère ...
<html><head><style></style></head><body> <div align='center'></div></body><script language='javascript'>function tab(col,lign){ this.tab = document.createElement("table"); this.autoid=1; this.lign = 0; this.largeur = 0; this.newCell = null; for(j=0;j<lign;j++) { this.newRow = this.tab.insertRow(-1); for(i=0;i<col;i++) { this.newCell = this.newRow.insertCell(i); this.newCell.innerHTML = " "; this.newCell.setAttribute("id","cel"+this.autoid); /* ############################# style de l'objet ################################### */ with(this.newCell.style) { borderStyle = 'solid'; borderWidth = '2px'; borderColor = "#000000"; backgroundColor="#ffffff"; width = '100px'; height = '50px'; textAlign = 'center'; } /* ############################# fonction de la cellule ################################### */ this.newCell.onclick = function () { if(this.style.backgroundColor=="#ffffff") { this.style.backgroundColor = "#fff000"; } else { this.style.backgroundColor="#ffffff"; } } this.newCell.onmouseover = function () { this.style.cursor = "pointer"; } // this.newCell.onmouseout = function () { this.style.backgroundColor = "#ffffff"; } this.autoid++; } } /* ############################# méthodes du tableau ################################### */ this.addtxt = function(id,text) { document.getElementById("cel"+id).innerHTML = text; } this.aligner = function(place) { this.tab.setAttribute("align",place); } /* ############################# méthodes des cellules ################################### */ this.defwcell = function(largeur) { for(i=1;i<this.autoid;i++) { document.getElementById("cel"+i).style.width = largeur; } document.body.appendChild(this.tab); } this.defhcell = function(h) { for(i=1;i<this.autoid;i++) { document.getElementById("cel"+i).style.height = h; } document.body.appendChild(this.tab); } this.aligner = function(pos) { this.tab.setAttribute("align",pos); document.body.appendChild(this.tab); } document.body.appendChild(this.tab); }var tab = new tab(10,10);tab.defwcell(50);tab.defhcell(50);tab.aligner("center");tab.addtxt(15,"coucou");</script></html>bon dernier jet et je m'arrête là... j'espère que ça vous aidera. voilà voilà bye
Se souvenir du profil
Mot de passe oublié ? / Activation de compteCréer un compte
1 598 458 membres 466 nouveaux aujourd'hui 15 439 membres club