【发布时间】:2015-12-22 12:47:45
【问题描述】:
我在一个 div 中有几个按钮,一旦单击它们就会显示一个值。我遇到的问题是:一旦单击按钮并显示一个值,它也会向下移动。我不确定如何防止这种情况发生。任何人都可以帮忙吗?这是我正在创建的示例的链接: http://codepen.io/anon/pen/eJzROE
<div id="gamebox">
<input type="button" id="one" onclick="clickBtn('one')"/>
<input type="button" id="two" onclick="clickBtn('two')"/>
<input type="button" id="three" onclick="clickBtn('three')"/>
<input type="button" id="four" onclick="clickBtn('four')"/>
<input type="button" id="five" onclick="clickBtn('five')"/>
<input type="button" id="six" onclick="clickBtn('six')"/>
<input type="button" id="seven" onclick="clickBtn('seven')"/>
<input type="button" id="eight" onclick="clickBtn('eight')"/>
<input type="button" id="nine" onclick="clickBtn('nine')"/>
</div>
#gamebox
{
height:460px;
width:460px;
border:2px solid red;
}
input
{
width:150px;
height:150px;
font-size:60px;
}
var player= 1;
function clickBtn(btn){
if(player == 1){
document.getElementById(btn).value = "X";
document.getElementById(btn).disabled = "disabled";
player -=1;
}
else {
document.getElementById(btn).value = "O";
document.getElementById(btn).disabled = "disabled";
player +=1;
}
}
【问题讨论】:
-
我在 FF43 中看不到任何移动?
-
@Storm - 我看到了你的问题。只有一个问题,你必须使用按钮吗? :) 否则我们可以使用 div 之类的其他东西,我会为你画一些很酷的东西。
-
@FrederikMoller - 是的,我可以使用别的东西。我只是尽力保持代码简单。
标签: javascript css html