Bonjour à tous, j'ai quelques problèmes avec le Javascript, je nage complet..
après de nombreuses heures de galère j'ai pu généré en procédurale un tableau qui génère aléatoirement des nombres pour une saisie amélioré d'un mot de passe.
voici mon source :
et j'aimerais avoir le meme résultat mais en objet de la facon suivante
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 document.getElementById("genereTab").innerHTML = genererTableau("tabmdp"); genRandomTableau("tabmdp"); ///// GENERE TABLEAU ////////// GENERE TABLEAU ////////// GENERE TABLEAU ///// ///// GENERE TABLEAU ////////// GENERE TABLEAU ////////// GENERE TABLEAU ///// function genererTableau(idtab) { var chaine="<table id='" + idtab + "'>"; for (i=0; i<5; i++) { // genere 5 lignes chaine+="<tr id='" + idtab + "l" + i + "'>"; for (j=0; j<5; j++) { // genere 5 colonnes chaine+="<td id='" + idtab + "c" + i + j + "'>" + "</td>"; } chaine+="</tr>"; } chaine+="</table>"; return chaine; } ///// RANDOM TABLEAU ////////// RANDOM TABLEAU ////////// RANDOM TABLEAU ///// ///// RANDOM TABLEAU ////////// RANDOM TABLEAU ////////// RANDOM TABLEAU ///// function genRandomTableau(idtabrand) { for (value=0; value<10; value++) { do { i= (Math.floor((5)*Math.random())); j= (Math.floor((5)*Math.random())); } while (document.getElementById(idtabrand + "c" + i + j).innerHTML!=""); document.getElementById(idtabrand + "c" + i + j).innerHTML = value; document.getElementById(idtabrand + "c" + i + j).onclick = evenementTab; // appel de la fonction evenementTab } } ///// EVENEMENT TABLEAU ////////// EVENEMENT TABLEAU ////////// EVENEMENT TABLEAU ///// ///// EVENEMENT TABLEAU ////////// EVENEMENT TABLEAU ////////// EVENEMENT TABLEAU ///// function evenementTab(event) { // crée l'interaction de la case, place la valeur dans "motdepasse" document.getElementById("motdepasse").value+=this.innerHTML; document.getElementById(event.target.id).style.backgroundColor = "red"; // POUR FIREFOX window.event.srcElement.style.backgroundColor = "red"; // POUR IE }
C'est notre prof qui a traduit cette classe, mais j'arrive vraiment pas a voir pour ma classe tableau.., si quelqu'un pouvais me mettre sur la voie
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 var utilisateur = new User("",""); // Création d'un Objet User ///// OBJET : UTILISATEUR ////////// OBJET : UTILISATEUR ////////// OBJET : UTILISATEUR ///// ///// OBJET : UTILISATEUR ////////// OBJET : UTILISATEUR ////////// OBJET : UTILISATEUR ///// function User(logi,mdp) { this.login=logi; this.motdepasse=mdp; if(typeof User.initialised=="undefined") { User.prototype.setlogin=function(logi) { this.login=logi; }; User.prototype.getlogin=function() { return this.login; }; User.prototype.setmotdepasse=function(mdp) { this.motdepasse=mdp; }; User.prototype.getmotdepasse=function() { return this.motdepasse; }; User.initialised=true; } }merci
Partager