我想从窗口提示中获取用户输入的值,并让它们显示在html页面上的段落标记中。我认为使用document.getElementById("idName").innerHTML
会起作用,但它不会显示用户输入的值。
以下是我在JavaScript页面上的代码。我已经调用了需要在页面上执行的方法。 :
var players = [];
var numberOfMoves = 0;
var currentPlayer = 0;
getPlayerNames(); //Get player names
setPlayerInformation(); //Set the names of the players in paragraph tags with id playerOneInformation and playerTwoInformation
function getPlayerNames()
{
players[0] = window.prompt("Please Enter Player 1: ", "");
players[1] = window.prompt("Please Enter Player 2: ", "");
}
function setPlayerInformation()
{
document.getElementById("playerOneInformation").innerHTML = players[0];
document.getElementById("playerTwoInformation").innerHTML = players[1];
}