Avrei un problema in js...
Ho creato questo piccolo codice, semplice semplice:
Ho cercato di semplificare il tutto, per usare solo tre bottoni, e sono arrivato a questo:codice:<script type="text/javascript"> <!-- function xre(x) { if (x == 1) { document.getElementById("crost1").innerHTML=1;}; else if (x == 2) { document.getElementById("crost1").innerHTML=2;}; else if (x == 3) { document.getElementById("crost1").innerHTML=3;}; } function xre2(y) { if (y == 1) { document.getElementById("crost2").innerHTML=1;}; else if (y == 2) { document.getElementById("crost2").innerHTML=2;}; else if (y == 3) { document.getElementById("crost2").innerHTML=3;}; } function xre3(z) { if (z == 1) { document.getElementById("crost3").innerHTML=1;}; else if (z == 2) { document.getElementById("crost3").innerHTML=2;}; else if (z == 3) { document.getElementById("crost3").innerHTML=3;}; } // --> </script> <table> <tr> <td id="crost1">0</td> <td id="crost2">0</td> <td id="crost3">0</td> </tr> </table> <input type="button" value="1" onclick="xre(1);"> <input type="button" value="2" onclick="xre(2);"> <input type="button" value="3" onclick="xre(3);"> <input type="button" value="1" onclick="xre2(1);"> <input type="button" value="2" onclick="xre2(2);"> <input type="button" value="3" onclick="xre2(3);"> <input type="button" value="1" onclick="xre3(1);"> <input type="button" value="2" onclick="xre3(2);"> <input type="button" value="3" onclick="xre3(3);">
Però, nel secondo codice, se premo uno dei tre pulsanti, mi viene modificato tutte e tre le celle contemporaneamente...codice:<script type="text/javascript"> <!-- function xre(x) { if (x == 1) { document.getElementById("crost1").innerHTML=1;}; else if (x == 2) { document.getElementById("crost1").innerHTML=2;}; else if (x == 3) { document.getElementById("crost1").innerHTML=3;}; } function xre2(y) { if (y == 1) { document.getElementById("crost2").innerHTML=1;}; else if (y == 2) { document.getElementById("crost2").innerHTML=2;}; else if (y == 3) { document.getElementById("crost2").innerHTML=3;}; } function xre3(z) { if (z == 1) { document.getElementById("crost3").innerHTML=1;}; else if (z == 2) { document.getElementById("crost3").innerHTML=2;}; else if (z == 3) { document.getElementById("crost3").innerHTML=3;}; } // --> </script> <table> <tr> <td id="crost1">0</td> <td id="crost2">0</td> <td id="crost3">0</td> </tr> </table> <input type="button" value="1" onclick="xre(1); xre2(1); xre3(1);"> <input type="button" value="2" onclick="xre(2); xre2(2); xre3(2);"> <input type="button" value="3" onclick="xre(3); xre2(3); xre3(3);">
Io vorrei invece che premendo uno dei tre pulsanti mi viene modificata la prima cella, se è stato fatto, premendo di nuovo uno dei tre bottoni mi venga modificata la seconda cella e stessa cosa se è stato fatto, premendo di nuovo si modifica la terza...
Ho provato usando l'istruzione if combinata con or, in modo da dire se la prima cella contiene o 1 o 2 o 3, fai la seconda funzione, ma non funziona...
Ho pensato se si può disattivare la funzione dopo averla eseguita, ma non sò come fare... Mi potete aiutare?

Rispondi quotando
