我想將JavaScript函數的結果打印到HTML/PHP頁面中的表格中。我嘗試使用「document.write(player1Name);」 但它沒有奏效。 因此,當我輸入的東西在文本框中 將某些東西從JavaScript打印到HTML/PHP頁面中的表格
這是打印的結果是我的劊子手主頁代碼:
<form id="Player1" class="Player1">
<input type="text" id="playerOneName"/>
</form>
<form id="Player2" class="Player2">
<input type="text" id="playerTwoName"/>
</form>
<button id="Enter" class="Enter" type="button" onclick="navigateToDifficultyForMultiPlayer()">
<a>Enter</a>
</button>
這是在我的多玩家頁面代碼表中:
<TABLE BORDER="5" WIDTH="20%" CELLPADDING="5" CELLSPACING="2" id="Score-Board">
<TR>
<caption id="table-title">Score Board</caption>
</TH>
</TR>
<TR ALIGN="CENTER">
<TH colspan="2"> <script> document.write(player1Name);</script> </TH>
<TH colspan="2"><script> var player2Name </script></TH>
</TR>
<TR ALIGN="CENTER">
<TH colspan="2">score</TH>
<TH colspan="2">score</TH>
</TR>
</TABLE>
這是我的Java Script代碼,我創建做我想做的事情(我覺得我已經做了右):
function navigateToDifficultyForMultiPlayer() {
//set player names in session
setPlayerNames();
//navigate to DifficultyForMultiPlayer page
location.href = "DifficultyForMultiPlayer.html";
}
function setPlayerNames() {
var firstPlayerName = document.getElementById("playerOneName").value;
var secondPlayerName = document.getElementById("playerTwoName").value;
console.log(firstPlayerName + " " + secondPlayerName);
sessionStorage.setItem("Player1Name", firstPlayerName);
sessionStorage.setItem("Player2Name", secondPlayerName);
}
function getPlayerNames(){
player1Name = sessionStorage.getItem("Player1Name");
player2Name = sessionStorage.getItem("Player2Name");
console.log(player1Name + " " + player2Name);
}
這是多數民衆贊成在全球範圍調用的JavaScript:我希望每個人都能
var player1Name;
var player2Name;
瞭解我想問的問題。請不要猶豫,告訴我我的問題是否有問題。我盡力妥善問的問題,僅供參考英語不是我的第一語言
如果我們的答案有幫助,請記得接受它們。謝謝。 – Cruiser