function User()
{
this.username = null;
this.password = null;
this.first = null;
this.last = null;
}
var userList = new Array();
userList[0] = new User();
userList[1] = new User();
userList[2] = new User();
userList[0].username = "Georgie19";
userList[1].username = "PaulC-87";
uesrList[2].username = "JamesHat";
userList[0].password = "georgepass101";
userList[1].password = "adminpaul-13";
userList[2].password = "jamesH7";
userList[0].first = "George";
userList[1].first = "Paul";
userList[2].first = "James";
userList[0].last = "Hordin";
userList[1].last = "Corman";
userList[2].last = "Haquel";
document.write(userList[0].username);
当我将它放入浏览器时,它显示为空白。我试图摆脱我不使用的东西,它会自动运行。我真的无法解决这个问题。我怀疑这是一个我无法找到的语法错误,请帮忙。 PS:我的HTML中没有问题
答案 0 :(得分:2)
userList
在此行上输入错误导致脚本错误导致代码无法运行:
uesrList[2].username = "JamesHat";
请学习查看调试控制台以查看您自己的脚本错误广告,这一点在第二天明确说明。
修复该错误后,您的脚本运行正常。
工作片段:
function User()
{
this.username = null;
this.password = null;
this.first = null;
this.last = null;
}
var userList = new Array();
userList[0] = new User();
userList[1] = new User();
userList[2] = new User();
userList[0].username = "Georgie19";
userList[1].username = "PaulC-87";
userList[2].username = "JamesHat";
userList[0].password = "georgepass101";
userList[1].password = "adminpaul-13";
userList[2].password = "jamesH7";
userList[0].first = "George";
userList[1].first = "Paul";
userList[2].first = "James";
userList[0].last = "Hordin";
userList[1].last = "Corman";
userList[2].last = "Haquel";
document.write(userList[0].username);