我正在嘗試更新我的探路者字符生成器,以便能夠使用HTML5的Web存儲器保存字符。我有一個用於生成角色的JavaScript文件。HTML5和Javascript字符保存
但是,我遇到了一些問題。我怎樣才能做到這一點,只有點擊我的「更新字符」按鈕才能更新已更新的內容?其次,最好的展示結果的方法是什麼?
這是我當前的代碼:
function SaveCharacter() {
makeCharacter();
if (typeof(Storage) !== "undefined") {
if (localStorage.used) {
alert("used was true.");
localStorage.name = name;
}
else {
localStorage.used = true;
localStorage.name = name;
localStorage.skill_points = num_skill_points;
localStorage.spells = num_spells;
localStorage.feats = num_feats;
localStorage.hitdie = hit_die;
localStorage.wealth = wealth;
localStorage.Class = Class;
// localStorage.Scores = new Array();
// for (var i = 0; i < n; i++) {
// localStorage.Scores[i] = ability_scores[i];
// }
}
document.getElementById("result").innerHTML="Character Name: " + localStorage.name;
}
else {
document.getElementById("result").innerHTML = "Sorry, your browser does not support web storage...";
}
}
function DeleteCharacter() {
localStorage.clear();
}
這一工作時,它改變了名稱,無論是否我已經刪除的字符或沒有。此外,document.getElementById("result").innerHTML="Character Name: " + localStorage.name;
不允許我一次更新多個字段。什麼是更好的方法來做到這一點?
[編輯] - Here is a link to the generator。