我正在使用JavaScript进行摇滚剪刀游戏。我从用户那里获得单选按钮的输入时遇到了一些麻烦。如果机器人赢了一轮,它也应该在他的分数上加1,现在每次都这样做。以下是我尝试过的代码:
HTML:
function playBot(){
var num = Math.floor((Math.random() * 4) + 1); // generate number between 1 and 3 which represents the item bot has chosen
console.log(num);
var rock = document.getElementById("rock").value;
var paper = document.getElementById("paper").value;
var scissors = document.getElementById("scissors").value;
var result = document.getElementById("result");
// 1 = rock, 2 = paper, 3 = scissors
if (rock.checked == true && num != 2){
pl1 = pl1 + 1;
document.getElementById("pl1").innerHTML = pl1;
} else if (paper.checked == true && num != 3){
pl1 = pl1 + 1;
document.getElementById("pl1").innerHTML = pl1;
} else if (scissors.checked == true && num != 1){
pl1 = pl1 + 1;
document.getElementById("pl1").innerHTML = pl1;
} else {
pl2 = pl2 + 1;
document.getElementById("pl2").innerHTML = pl2;
}
}
和JavaScript:
for
我已尝试使用accordionPanel
循环执行此操作,但这也不起作用。我尝试过的来源:How to get value of selected radio button?
Get Radio Button Value with Javascript
http://www.w3schools.com/jsref/prop_radio_checked.asp
提前致谢