Web 開発用のコードの作成方法を学んでいるのですが、問題が発生しました。ほぼ同一の 2 行のコードで、異なる結果が得られます。
for(i=0; i<=lunarSpells.length; i++){
document.getElementById(lunarSpells[i]).innerHTML =
Math.ceil(xpLeft/document.getElementById(lunarSpells[i]+"XP").innerHTML);
}
for(i=0; i<=standardSpells.length; i++){
document.getElementById(standardSpells[i]).innerHTML =
Math.ceil(xpLeft/document.getElementById(standardSpells[i]+"XP").innerHTML);
}
その重要性は不明ですが、アイデアは、配列から要素を取得し、ドキュメント内で見つけて、それに応じてテーブルに入力することです。配列は次のとおりです。
var lunarSpells = ["cureOther", "NPCContact", "curePlant", "monsterExamine", "bakePie", "cureMe", "TGMoonclan",
"TPMoonclan", "TGBarbarian", "superglass", "TPKhazard", "TGKhazard", "dream", "stringJewellery",
"statRestorePotShare", "statSpy", "TPBarbarian", "TPWaterbirth", "cureGroup", "TGWaterbirth", "humidify",
"hunterKit", "fertileSoil", "plankMake", "TPCatherby", "TGFishingGuild", "TGCatherby",
"boostPotionShare", "TPIcePlateau", "energyTransfer", "healOther", "TGIcePlateau", "vengeanceOther",
"vengeance", "healGroup", "spellbookSwap", "magicImbue", "TPFishingGuild"]
var standardSpells = ["confuse", "sapphire", "weaken", "bananas", "curse", "lowAlch", "TPVarrock", "emerald", "TPLumbridge", "TPFalador", "TPHouse",
"superheat", "TPCamelot", "ruby", "TPArdougne", "highAlch", "earth", "water", "diamond", "TPWatchtower",
"peaches", "TPTrollheim", "fire", "TPApe", "vulnerability", "air", "dragonstone", "enfeeble", "TOLumbridge", "stun",
"TOFalador", "onyx", "TOCamelot"]
私の質問は、なぜ lunarspells 変数が機能しているのに、standardspells 変数が機能していないのですか? 私はまだHTMLとJSにまったく慣れていないので、どんな助けも大歓迎です。