这与我之前的问题有关,但是它略有不同,并且是一个全新的问题...我有一个数组,经过一些不错的 PHP 之后,它看起来像这样:
var series = {
"001":{
"game":"Portal 2",
"name":"Portal 2"
},
"002":{
"game":"Minecraft",
"name":"241"
},
"003":{
"game":"Minecraft",
"name":"HackMine"
},
"004":{
"game":"Mass Effect 3",
"name":"Mass Effect 3"
},
"005":{
"game":"League of Legends",
"name":"League of Legends"
},
"006":{
"game":"Half Life 2",
"name":"The Hidden: Source"
},
"007":{
"game":"Skyrim",
"name":"Modded Skyrim"
}
}
这一点填充得很好......现在我的问题是当这个函数被调用时,它总是给出game
并且name
值undefined
function seriesIdOnBlur()
{
var id = parseInt(document.getElementById("series_id").value);
if (series[id] == null)
{
var message = "The Series ID you input was invalid";
}
else
{
var seriesId = series[id];
var game = seriesId['game'];
var name = seriesId['name'];
var message = "You've inputted the id for the game: " + game + " for the series: " + name;
}
document.getElementById("series_id_check").innerHTML = message;
}