任何一個人看到,當我到達這條線什麼不順心......爲什麼控制檯返回「TypeError:newIndustry爲null」?
newIndustry.innerHTML = industryNews[generateRandomNumber()-1]
}
這裏是我的代碼JS(我只是刪除文本中的H1與#industryNews
)
var industryNews = [];
industryNews[0] = "Lorem ipsum dolor <strong>sit</strong> amet, consectetur adipisicing elit. Optio, ut, maxime, eum, fugit dolor nulla cupiditate beatae sapiente dignissimos accusamus cumque fuga alias accusantium praesentium nisi placeat quam ad eius.";
industryNews[1] = "Lorem ipsum dolor <strong>sit</strong> amet, consectetur adipisicing elit. Provident, consequuntur, officia veritatis molestias odio nobis minima iste id tenetur possimus magni nisi error enim minus aperiam? Minus, iure delectus cumque.";
industryNews[2] = "Lorem ipsum dolor <strong>sit</strong> amet, consectetur adipisicing elit. Sint, in, qui voluptatibus voluptas inventore recusandae non quos adipisci dolor beatae dolore saepe quaerat exercitationem dolores delectus quo pariatur. Quae, quidem.";
industryNews[3] = "Lorem ipsum dolor <strong>sit</strong> amet, consectetur adipisicing elit. Assumenda, sed, laborum, quisquam rerum quo non aspernatur necessitatibus soluta id debitis impedit corporis magnam praesentium ab odit dicta aperiam autem consequuntur!";
var newIndustry = document.getElementById("industryNews");
// generate a # between 1 &4
function generateRandomNumber(){
return Math.floor(Math.random()*(4)+1);
}
function updateindustryNews() {
// var interval = generateRandomNumber();
newIndustry.innerHTML = industryNews[generateRandomNumber()-1]
}
updateindustryNews();
setInterval(updateindustryNews,4000);
當腳本執行時,你有'id =「industryNews」'元素嗎? – Amadan
http://ctec.clark.edu/~h.nelson5/ctec126/project/final/ – user2822565
你爲什麼要發佈一個鏈接?回答@ Amadan的問題怎麼樣? –