Ich mache ein Tic-Tac-Toe-Spiel und ich möchte jetzt wissen, wie ich einen Button nach einem Klick unclickable machen kann. hier ist das Spielfeld:lösen Sie eine Klick-Funktion nach der Verwendung
<div id="gamefield">
<table border="0">
<tr>
<td><img alt="" title="" src="img/empty.jpg" /></td>
<td><img alt="" title="" src="img/empty.jpg" /></td>
<td><img alt="" title="" src="img/empty.jpg" /></td>
</tr>
<tr>
<td><img alt="" title="" src="img/empty.jpg" /></td>
<td><img alt="" title="" src="img/empty.jpg" /></td>
<td><img alt="" title="" src="img/empty.jpg" /></td>
</tr>
<tr>
<td><img alt="" title="" src="img/empty.jpg" /></td>
<td><img alt="" title="" src="img/empty.jpg" /></td>
<td><img alt="" title="" src="img/empty.jpg" /></td>
</tr>
</table>
</div>
ist dies die randomstart Funktion:
var randomStart = Math.floor(Math.random() * 2);
dies ist die Funktion für das Spielfeld:
$("#gamefieldtr td").click(function() {
if ($(".game-button").html() == "Start spel") {
alert("you can't start");
} else {
if(randomStart == 0){
var val = $(this).children().attr('src', 'img/cross.jpg');
randomStart = 1;
$("#playerTurn").html("1");
$("#turnImg").attr("src", "img/circle.jpg");
}
else {
var val = $(this).children().attr('src', 'img/circle.jpg');
randomStart = 0;
$("#playerTurn").html("0");
$("#turnImg").attr("src", "img/cross.jpg");
$('src', 'img/circle.jpg').unbind("click");
}
}
});
Mögliche Duplikat [Beste Art und Weise einen Event-Handler in jQuery zu entfernen?] (Http://stackoverflow.com/questions/209029/best-way-to-remove-an-event-handler- in-jquery) – ppasler
Markieren Sie die Schaltfläche als angeklickt mit einer Klasse und geben Sie false für den Event-Handler zurück, wenn die Schaltfläche die Klasse hat? – tmslnz