我使用javascript来输出图像,在FF和Chrome中一切正常,但在IE中只有第一张图像在第一次加载页面时被追加刷新页面后,所有图像都会被添加。
Javascript来输出图像:
$.getJSON("php/v.php?"+Math.random(),function(data){
$.each(data,function(l){
if(data[l]['s']==1){
$("#img"+(l+1)).append("<img src='"+data[l]['img']+"' />");
}
});
});
从从v.php IE9开发工具响应:
[{"img":"https:\/\/www.example.com\/example.jpg","s":"1"},{"img":"https:\/\/www.example.com\/example.jpg","s":"1"},{"img":"https:\/\/www.example.com\/example.jpg","s":"1"}]
所以问题应该已经引起各个元素,而不是的getJSON。 在stackoverflow上发现很多类似的问题,但没有那样的 (http://stackoverflow.com/questions/7785138/each-method-only-applies-to-first-element-in-ie,http://stackoverflow.com/questions/4664190/javascript-each-loop-over-json-only-getting-first-element),但在我的情况下,问题也发生在IE9中。
你可以尝试把你的Javascript中的$(document)。就绪(函数(){} –