html 로컬 저장소로 게임을 할 때 플레이어가 얻는 점수를 추가하고 싶습니까? 어떻게해야합니까? 게다가, 만약 누군가에게 너무 많은 문제가되지 않는다면, 나는 어떻게 현지인 저장소에서 점수를 검색하여 순위 테이블에 넣을 수 있습니까? 대부분의 코드 그냥 내가 볼 수 없습니다 몇 가지 내가 당신이 쓴 게임을보고 정말 감동 받았습니다,점수를 로컬 저장소로 보내려면 어떻게해야합니까?
https://jsfiddle.net/gugui3z24/ab4gaf15/2/
/* This function is called when a logged in user
plays the game and gets a score */
function updateScore(newScore) {
//Get the JavaScript object that holds the data for the logged in user
var usrObj = JSON.parse(localStorage[localStorage.loggedInUser]);
//Update the user object with the new top score
/* NOTE YOU NEED TO CHANGE THIS CODE TO CHECK TO SEE IF THE NEW SCORE
IS GREATER THAN THE OLD SCORE */
usrObj.topscore = newScore;
//Put the user data back into local storage.
localStorage[localStorage.loggedInUser] = JSON.stringify(usrObj);
}
/* Loads the rankings table.
This function should be called when the page containing the rankings table loads */
function showRankingsTable() {
//Get a reference to the div that will hold the rankings table.
var rankingDiv = document.getElementById("RankingsTable");
//Create a variable that will hold the HTML for the rankings table
var htmlStr = "";
//Add a heading
htmlStr += "<h1>Rankings Table</h1>";
//Add the table tag
htmlStr += "<table>";
//Work through all of the keys in local storage
for (var key in localStorage) {
//All of the keys should point to user data except loggedInUser
if (key !== "loggedInUser") {
//Extract object containing user data
//Extract user name and top score
htmlStr += "David";
//Add a table row to the HTML string.
}
}
//Finish off the table
htmlStr += "</table>";
당신은 무엇을 이해하지? – SLaks
점수를 보내는 방법 사용자가 localstorage에 도착한 다음 localstorage에서 점수를 검색하고 다른 사용자의 점수도 표시되는 순위에 입력하십시오 –