我正在尝试更新我的探路者字符生成器,以便能够使用 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;
不允许我一次更新多个字段。有什么更好的方法来做到这一点?
[编辑] -这是生成器的链接。