0
這裏是一段代碼,我在控制檯出現錯誤,任何人都可以指出我在哪裏做錯了?提前致謝。Uncaught TypeError:無法讀取未定義的屬性'nextSibling'
var intervalID = setInterval(function() {
// every 4 seconds execute following
var visibleWord = document.getElementsByClassName('visible')[0],
nextWord = visibleWord.nextSibling;
// check if nextSibling is textnode (whitespace) - if so get next next sibling.
if (nextWord.nodeType == 3) nextWord = nextWord.nextSibling;
// if there is a next node
if (!(nextWord == null)) {
visibleWord.setAttribute('class', 'hidden');
nextWord.setAttribute('class', 'visible');
} else {
clearInterval(intervalID);
}
}, 4000)
檢查空訪問前/未定義nextSibling – awd
_「檢查nextSibling是否爲textnode(空格) - 如果是這樣,請獲取下一個下一個兄弟」__> [.nextElementSibling](https://developer.mozilla.org/en-US/docs/Web/API/NonDocumentTypeChildNode/ nextElementSibling) – Andreas