A voir également:
- [ javascript ] erreur avec la fonction erase
- Fonction si et - Guide
- Erreur 0x80070643 - Accueil - Windows
- Erreur 0x80070643 Windows 10 : comment résoudre le problème de la mise à jour KB5001716 - Accueil - Windows
- Telecharger javascript - Télécharger - Langages
- Erreur 1001 outlook - Accueil - Bureautique
2 réponses
tien j eme suis dit ke si je meté la page en entier sa seré peut etre mieu:
<script type="text/javascript" language="javascript">
var i = 1;
var table = [3, 4, 5, 6, 7, 8, 9, 10, 11];
var score1 = 0;
var score2 = 0;
function crond(change, a){
if(i == 1){
document.getElementById("case" + change).src='x.jpg';
document.getElementById('titrejoueur').innerHTML='Joueur 2 Joue';
table[parseInt(a)] = '1';
i=2;
}
else {
document.getElementById("case" + change).src='o.jpg';
document.getElementById('titrejoueur').innerHTML="Joueur 1 Joue";
i = 1;
table[parseInt(a)] = '2';
}
document.getElementById("case" + change).onclick='';
if (table[0] == table[1] && table[0]==table[2] && table[0] == 1 || table[3] == table[4] && table[3]==table[5] && table[3] == 1 || table[6] == table[7] && table[6]==table[8] && table[6] == 1 || table[0] == table[3] && table[0]==table[6] && table[0] == 1 || table[1] == table[4] && table[1]==table[7] && table[1] == 1 || table[2] == table[5] && table[2]==table[8] && table[2] == 1 || table[0] == table[4] && table[0]==table[8] && table[0] == 1 || table[2] == table[4] && table[2]==table[6] && table[2] == 1)
{alert("victoire joueur 1");
score1++;
document.getElementById('score1').innerHTML = score1;
}
if ( table[0] == table[1] && table[0] == table[2] && table[0] == 2 || table[3] == table[4] && table[3] == table[5] && table[3] == 2 || table[6] == table[7] && table[6] == table[8] && table[6] == 2 || table[0] == table[3] && table[0] == table[6] && table[0] == 2 || table[1] == table[4] && table[1] == table[7] && table[1] == 2 || table[2] == table[5] && table[2] == table[8] && table[2] == 2 || table[0] == table[4] && table[0] == table[8] && table[0] == 2 || table[2] == table[4] && table[2] == table[6] && table[2] == 2)
{alert("victoire joueur 2");
score2++;
document.getElementById('score2').innerHTML = score2;
}
}
function erase () {
table[0] = "0";
table[1] = "0";
table[2] = "0";
table[3] = "0";
table[4] = "0";
table[5] = "0";
table[6] = "0";
table[7] = "0";
table[8] = "0";
document.getElementById("case0").src='Capturer.jpg';
document.getElementById("case1").src='Capturer.jpg';
document.getElementById("case2").src='Capturer.jpg';
document.getElementById("case3").src='Capturer.jpg';
document.getElementById("case4").src='Capturer.jpg';
document.getElementById("case5").src='Capturer.jpg';
document.getElementById("case6").src='Capturer.jpg';
document.getElementById("case7").src='Capturer.jpg';
document.getElementById("case8").src='Capturer.jpg';
}
</script>
</head>
<body>
<div class="title">
<h3 id="titrejoueur"> Joueur 1 joue </h3>
</div>
<div class="container">
<br/><br/><br/>
<h1>MORPION</h1>
<br/><br/><br/>
<table border="2">
<tr>
<td><input type="image" src="Capturer.JPG" id="case01" onclick="crond('01', '0')" alt="depart"/></td>
<td><input type="image" src="Capturer.JPG" id="case02" onclick="crond('02', '1')" alt="depart"/></td>
<td><input type="image" src="Capturer.JPG" id="case03" onclick="crond('03', '2')" alt="depart"/></td>
</tr>
<tr>
<td><input type="image" src="Capturer.JPG" id="case04" onclick="crond('04', '3')" alt="depart"/></td>
<td><input type="image" src="Capturer.JPG" id="case05" onclick="crond('05', '4')" alt="depart"/></td>
<td><input type="image" src="Capturer.JPG" id="case06" onclick="crond('06', '5')" alt="depart"/></td>
</tr>
<tr>
<td><input type="image" src="Capturer.JPG" id="case07" onclick="crond('07', '6')" alt="depart"/></td>
<td><input type="image" src="Capturer.JPG" id="case08" onclick="crond('08', '7')" alt="depart"/></td>
<td><input type="image" src="Capturer.JPG" id="case09" onclick="crond('09', '8')" alt="depart"/></td>
</tr>
</table>
</div>
<div class="tab2">
<table border="2">
<tr><th colspan=2>SCORE</th>
</tr>
<tr>
<th>Player 1</th>
<th>Player 2</th>
</tr>
<tr>
<th id="score1">0</th>
<th id="score2">0</th>
</tr>
</table>
</div>
<div class="refresh">
<input type="button" value="New Game" onClick="erase();" />
</div>
</body>
</html>
<script type="text/javascript" language="javascript">
var i = 1;
var table = [3, 4, 5, 6, 7, 8, 9, 10, 11];
var score1 = 0;
var score2 = 0;
function crond(change, a){
if(i == 1){
document.getElementById("case" + change).src='x.jpg';
document.getElementById('titrejoueur').innerHTML='Joueur 2 Joue';
table[parseInt(a)] = '1';
i=2;
}
else {
document.getElementById("case" + change).src='o.jpg';
document.getElementById('titrejoueur').innerHTML="Joueur 1 Joue";
i = 1;
table[parseInt(a)] = '2';
}
document.getElementById("case" + change).onclick='';
if (table[0] == table[1] && table[0]==table[2] && table[0] == 1 || table[3] == table[4] && table[3]==table[5] && table[3] == 1 || table[6] == table[7] && table[6]==table[8] && table[6] == 1 || table[0] == table[3] && table[0]==table[6] && table[0] == 1 || table[1] == table[4] && table[1]==table[7] && table[1] == 1 || table[2] == table[5] && table[2]==table[8] && table[2] == 1 || table[0] == table[4] && table[0]==table[8] && table[0] == 1 || table[2] == table[4] && table[2]==table[6] && table[2] == 1)
{alert("victoire joueur 1");
score1++;
document.getElementById('score1').innerHTML = score1;
}
if ( table[0] == table[1] && table[0] == table[2] && table[0] == 2 || table[3] == table[4] && table[3] == table[5] && table[3] == 2 || table[6] == table[7] && table[6] == table[8] && table[6] == 2 || table[0] == table[3] && table[0] == table[6] && table[0] == 2 || table[1] == table[4] && table[1] == table[7] && table[1] == 2 || table[2] == table[5] && table[2] == table[8] && table[2] == 2 || table[0] == table[4] && table[0] == table[8] && table[0] == 2 || table[2] == table[4] && table[2] == table[6] && table[2] == 2)
{alert("victoire joueur 2");
score2++;
document.getElementById('score2').innerHTML = score2;
}
}
function erase () {
table[0] = "0";
table[1] = "0";
table[2] = "0";
table[3] = "0";
table[4] = "0";
table[5] = "0";
table[6] = "0";
table[7] = "0";
table[8] = "0";
document.getElementById("case0").src='Capturer.jpg';
document.getElementById("case1").src='Capturer.jpg';
document.getElementById("case2").src='Capturer.jpg';
document.getElementById("case3").src='Capturer.jpg';
document.getElementById("case4").src='Capturer.jpg';
document.getElementById("case5").src='Capturer.jpg';
document.getElementById("case6").src='Capturer.jpg';
document.getElementById("case7").src='Capturer.jpg';
document.getElementById("case8").src='Capturer.jpg';
}
</script>
</head>
<body>
<div class="title">
<h3 id="titrejoueur"> Joueur 1 joue </h3>
</div>
<div class="container">
<br/><br/><br/>
<h1>MORPION</h1>
<br/><br/><br/>
<table border="2">
<tr>
<td><input type="image" src="Capturer.JPG" id="case01" onclick="crond('01', '0')" alt="depart"/></td>
<td><input type="image" src="Capturer.JPG" id="case02" onclick="crond('02', '1')" alt="depart"/></td>
<td><input type="image" src="Capturer.JPG" id="case03" onclick="crond('03', '2')" alt="depart"/></td>
</tr>
<tr>
<td><input type="image" src="Capturer.JPG" id="case04" onclick="crond('04', '3')" alt="depart"/></td>
<td><input type="image" src="Capturer.JPG" id="case05" onclick="crond('05', '4')" alt="depart"/></td>
<td><input type="image" src="Capturer.JPG" id="case06" onclick="crond('06', '5')" alt="depart"/></td>
</tr>
<tr>
<td><input type="image" src="Capturer.JPG" id="case07" onclick="crond('07', '6')" alt="depart"/></td>
<td><input type="image" src="Capturer.JPG" id="case08" onclick="crond('08', '7')" alt="depart"/></td>
<td><input type="image" src="Capturer.JPG" id="case09" onclick="crond('09', '8')" alt="depart"/></td>
</tr>
</table>
</div>
<div class="tab2">
<table border="2">
<tr><th colspan=2>SCORE</th>
</tr>
<tr>
<th>Player 1</th>
<th>Player 2</th>
</tr>
<tr>
<th id="score1">0</th>
<th id="score2">0</th>
</tr>
</table>
</div>
<div class="refresh">
<input type="button" value="New Game" onClick="erase();" />
</div>
</body>
</html>
Bonjour,
document.getElementById("case0").src='Capturer.jpg';
document.getElementById("case1").src='Capturer.jpg';
document.getElementById("case2").src='Capturer.jpg';
<input type="image" src="Capturer.JPG" id="case01" onclick="crond('01', '0')" alt="depart"/></td>
<td><input type="image" src="Capturer.JPG" id="case02" onclick="crond('02', '1')" alt="depart"/></td>
<td><input type="image" src="Capturer.JPG" id="case03" onclick="crond('03', '2')" alt="depart"/>
tes id ne sont pas identiques, dans les input tu as case01 case 02 etc..
et dans get ElementbyId(... du javascript tu as case0 case 1 case 2 etc..
c'est comme une variable il faut absolument le même nom avec la même casse
@lain
document.getElementById("case0").src='Capturer.jpg';
document.getElementById("case1").src='Capturer.jpg';
document.getElementById("case2").src='Capturer.jpg';
<input type="image" src="Capturer.JPG" id="case01" onclick="crond('01', '0')" alt="depart"/></td>
<td><input type="image" src="Capturer.JPG" id="case02" onclick="crond('02', '1')" alt="depart"/></td>
<td><input type="image" src="Capturer.JPG" id="case03" onclick="crond('03', '2')" alt="depart"/>
tes id ne sont pas identiques, dans les input tu as case01 case 02 etc..
et dans get ElementbyId(... du javascript tu as case0 case 1 case 2 etc..
c'est comme une variable il faut absolument le même nom avec la même casse
@lain