我正在使用imageUploaded.js庫,並在chrome dev中出現錯誤。 我已經粘貼下面的代碼的大片段,但在鉻強調了錯誤的路線是:爲什麼我會在我的腳本中獲取「Uncaught TypeError:無法讀取屬性'nodeName'null」?
if (elem.nodeName === 'img') {
我瞭解基本的JS,但不能完全地按照所發生的事情在這個庫中,所以我不確定這個錯誤意味着什麼或如何解決它。
ImagesLoaded.prototype = new EventEmitter();
ImagesLoaded.prototype.options = {};
ImagesLoaded.prototype.getImages = function() {
this.images = [];
// filter & find items if we have an item selector
for (var i=0, len = this.elements.length; i < len; i++) {
var elem = this.elements[i];
// filter siblings
if (elem.nodeName === 'img') {
this.addImage(elem);
}
// find children
// no non-element nodes, #143
var nodeType = elem.nodeType;
if (!nodeType || !(nodeType === 1 || nodeType === 9 || nodeType === 11)) {
continue;
}
var childElems = elem.querySelectorAll('img');
// concat childElems to filterFound array
for (var j=0, jLen = childElems.length; j < jLen; j++) {
var img = childElems[j];
this.addImage(img);
}
}
};
在'ImagesLoaded.prototype.getImages'的頂部放置一個'console.log(this.elements);'。有人向元素列表添加一個「null」而不是實際的元素。 – Rudie 2014-10-19 01:27:47
這意味着您正在嘗試查找'nodeName'的元素/節點不存在。 – 2014-10-19 01:28:13