-3
我需要保留authorId = 1的循環中的值,然後在下一個循環(authorId = 3)中將其作爲另一個值打印出來。我的意思是我需要保留authorSurname.value(id = 1)並將其作爲secondAuthor.value作爲循環(authorId = 3)打印出來,因爲在循環(authorId = 3)中,字符串authorSurname需要另一個值。你能告訴我如何解決它?使用JavaScript從前一個循環獲得價值
if(authorId === 0) {
div.innerHTML = firstAuthorSurname.value + year.value + page.value + pageOtherValue;
}
else if (authorId === 1) {
div.innerHTML = firstAuthorSurname.value + " i " + authorSurname.value + " (" + year.value + ");
var secondAuthorSurname = authorSurname.value;
}
else if (authorId === 2) {
return secondAuthorSurname;
div.innerHTML = firstAuthorSurname.value + ", " + secondAuthorSurname.value + " and " + authorSurname.value + " (" + year.value + ") " + firstAuthorSurname.value + ", " + secondAuthorSurname.value + " and " + authorSurname.value + ", " + year.value + ")" + firstAuthorSurname.value + ", " + secondAuthorSurname.value + " and " + authorSurname.value + ", " + year.value + ") showed that... ";
}
您的示例代碼不包含循環 – rekire