这已经让我紧张了 3 个晚上......我不知道为什么它在 IE9 中有效,但在 IE8 中无效。当我在 IE8 上运行它时,我不断收到此错误:
SCRIPT5007:无法获取属性“src”的值:对象为空或未定义
当我尝试调试时,我得到这条线是原因->
var map_locations = [], container = document.getElementById('renting-map-js'),
c = container.children, l = c.length, i, obj, p, m, j;
//loop through all child nodes
for ( i = 0; i < l; i++) {
obj = {};
//highlights this line
obj.img = c[i].getElementsByTagName('img')[0].src;
p = c[i].getElementsByTagName('p');
m = p.length;
for ( j = 0; j < m; j++)
obj[p[j].className] = p[j].firstChild.nodeValue;
map_locations[i] = obj;
console.log(obj);
}
</p>