我是新的JavaScript和我有了解信息,從設定到一個數組的外部記錄如何得到掙扎。我希望有人能告訴我我做錯了什麼。我剛剛起步,並沒有在編碼世界學到很多東西,所以下面是很枯燥的骨頭。任何幫助表示讚賞!插入記錄數組中的JavaScript(介紹到JavaScript的學生)
這是應該發生的情況:
- 打開
recordset
- 遍歷
recordset
- 對於在
recordset
- 循環每條記錄通過
arrayZipCode[]
- 如果郵政編碼是獨一無二的,加到
arrayZipCode[]
- 循環每條記錄通過
- 輸出
arrayZipCode
在HTML
這裏是我的代碼(這一切都來的雜草後,我進入記錄集):
// Declare global variables
var arrayZipCode = []; // Array
var zipCodeRecords; // Access to database
var index; // This is to capture the array slots and count loops
var displayResults; // Reference to list set up from HTML
var zipCode; // value of zip code
var valueFound; // boolean
// Set loop values
index = 0;
// Set display to reference html page
var displayResultsAs;
// Open the record set
function initializeZipCodeRecords() {
zipCodeRecords = openZipCodeStudyRecordSet();
}
// Loop through the record set
function readNextZipCodeRecord() {
while (zipCodeRecords.readNextRecord()) {
zipCode = zipCodeRecords.getSampleZipCode();
// For each record in the recordset:
// Loop through arrayZipCode
// If zip code is unique, add to arrayZipCode
// Output arrayZipCode in HTML
if (arrayZipCode[arrayZipCode.length] = 0) {
arrayZipCode[index] = zipCode;
} else {
while (index < arrayZipCode.length) {
// The results in alert are ALL codes, not only unique codes. Why?
if (zipCode !== arrayZipCode[index]) {
arrayZipCode[index] += zipCode;
// alert(arrayZipCode + "-" + arrayZipCode.length); // Interesting results (75213,91343,10024-3)
}
index ++;
}
}
}
}
function displayUniqueZipCodeList() {
// Not working; moved to main module
}
/*
Main Function Module
*/
function project5Part1() {
initializeZipCodeRecords();
readNextZipCodeRecord();
displayResults = document.getElementById("displayResultsId");
displayResults.innerHTML += "<li>";
+ arrayZipCode[index]
+ "</li>";
作業...... – 2011-12-19 17:00:32
@Felix我想是這樣 「(介紹到JavaScript的學生)」 – hunter 2011-12-19 17:01:00