【发布时间】:2015-09-13 16:34:07
【问题描述】:
我正在尝试制作井字游戏,我有 2 个按钮(单人游戏和 2 个玩家),我需要传递一个 int 供用户选择(取决于选择的按钮)并更改我的 js 中的值,
我的html:
<body onload="startGame(i);"> //this is the parameter i want to use
<table>
// code......
</table>
</br>
<div id= "menu" class="animated bounceInLeft"> <!-- Buttons -->
<a href = "javascript:startGame(1);" class = "animated shake">Single player</a> // the single player button
<a href = "javascript:startGame(2);" class = "animated shake">Two players</a> // to 2 players button
</div>
</body>
</html>
js:
var choise = 0; //global
function startGame(i){
if (i == 1)
choise = 1; //change according to parameter
else
choise = 1;
}
有可能吗?
谢谢!
【问题讨论】:
标签: javascript html function