Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我制作了一个井字游戏我有这个按钮,但我想计算用户点击它的次数,这样当点击次数 = 8 并且没有确定获胜者时,我可以将它用作我的平局游戏条件。如何传递和增加单击此按钮的次数?
我要使用javascript onclick 事件吗?
print('<input type="submit" name="submit_button" value = "Go">'); if(isset($_POST[submit_button])) { do stuff }
PHP 不会在这里解决您的问题,因为它只是服务器端。numClicks在您的 JavaScript 中声明一个变量,并将其更改input为:
numClicks
input
<input type="submit" name="submit_button" onclick="increaseClicks()" value = "Go">
然后你可以定义increaseClicks为
increaseClicks
function increaseClicks(){ numClicks++; if(numClicks >= 8){ //dostuff } }