2016-04-10 94 views
-2
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不會打印對象屬性

+1

* 「我試圖擺脫我不使用的東西」 *,哪些東西? – JCOC611

+0

'uesrList'真的是你在控制檯上試過的嗎? (第一個塊分配給'.username','uesrList [2] .username = ...') –

+1

另外,不確定你的應用程序到底是什麼,但知道在JavaScript中以純文本存儲密碼等同於告訴用戶每個人的密碼都是安全的。 – JCOC611

回答

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);

+0

通過說「我可以在控制檯中查看」,這是什麼意思?什麼控制檯?我只是在Windows中將其作爲文件運行,並且它出現在瀏覽器中。 – Mineohmight

+0

@mineohmight - 請參閱https://developer.chrome.com/devtools/docs/console – jfriend00