我有一個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中移動的任何東西? – Teemu
@Storm - 我看到你的問題。只有一個問題,你需要使用按鈕嗎? :)否則,我們可以使用其他東西,如divs和生病吸引你很酷。 –
@FrederikMoller - 是的,我可以使用別的東西。我只是盡我所能讓代碼簡單。 – Storm