我不能得到的代碼返回對象和數組中保存要保存的數組中的對象,第一個功能是保存在陣列內的歌曲和第二功能它來搜索歌曲已保存在陣列中我的功能不會返回
function save() {
//loop to keep adding songs within the array
var addSong = //create the object inside the function
{
title: document.number.title.value,
artist: document.number.artist.value,
col: document.number.col.value,
dur: document.number.dur.value
};
//output the song title of the saved song
document.number.saved.value = addSong.title;
return addSong;
}
//----------------------------------------------------------
var sTitle = document.searchSong.searchTitle.value; // assigning the search box to 'sTitle'
var library = new Array() //array to store each song
var song = addSong.title;
//-----------------------------------------------------------
//function to search for a song saved in the music() array
function search() {
//if statement to compare the inputs and see if the song is in the
library
if (sTitle == song) {
//if the song title is there then it is output
document.searchSong.result.value = song;
} else {
//if not then 'no song' is output instead
document.searchSong.result.value = "no song";
}
}
爲什麼所有這些屬性都添加到'document'中? – adeneo 2015-03-18 21:54:11
因爲採用的形式讓用戶輸入IM到陣列 – 2015-03-18 21:55:50
內保存這是整個腳本?因爲如果是這樣,你需要調用函數「保存()」,並試圖訪問它的「標題」屬性前轉讓其結果addSong。 – oLeduc 2015-03-18 21:56:50