我正在学习基础转弯游戏,并且想要拥有的是 JS中的交换玩家转弯功能。
我知道我需要什么,但我不知道怎么做,我需要尽可能简单。我只需要一个 div来显示转向 和一个 按钮来改变 。
我刚刚找到了很老的例子,我打赌有新的解决方案就像我想要的那样简单:)
代码的一部分:
<SCRIPT name = "JavaScript">
function variables(){
t = 1;
return;
whogoesnow = "Turn player 1"
}
function win(){ if (...) alert ("player 1: won the game !!!");
if (...) alert ("player 1: won the game !!!");}
function turnchange(t){
if (change == 1) {
if (t == 0){
t = 1;
whogoesnow = "turn: player " + 1
}
else {
t = 0;
whogoesnow = "turn: player " + 2
}
}
else {
t = t;
}
change = 1
return (t);
}
<script>
<SCRIPT name = "JavaScript">
variables();
</SCRIPT>
FORM>
<input type = "button" name = "whoseturn" value = "Turn: player 1">
我希望它可以给出我需要的意思,我接受任何类似链接,其他来源等等。
从现在开始,请求阅读并留下帮助:D
答案 0 :(得分:1)
$('#button').on('click', function(){
$('#turn').toggleClass('a');
});
&#13;
#turn .turn_a{display:none}
#turn.a .turn_a{display:block}
#turn.a .turn_b{display:none}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="turn">
<div class="turn_a">Player A</div>
<div class="turn_b">Player B</div>
</div>
<button id="button">Change turn</button>
&#13;