此错误有什么问题
TypeError:条目未定义
Firefox浏览器中出现此错误
<script type='text/javascript'>
//<![CDATA[
function showlatestpostswiththumbs(json) {
document.write('<div class="terbaru">');
for (var i = 0; i < posts_no; i++) {
var entry = json.feed.entry[i];
var posttitle = entry.title.$t;
var postsurl;
if (i == json.feed.entry.length) break;
for (var k = 0; k < entry.link.length; k++) {
if (entry.link[k].rel == 'replies' && entry.link[k].type == 'text/html') {
var commentstext = entry.link[k].title;
var commentsurl = entry.link[k].href;
}
if (entry.link[k].rel == 'alternate') {
postsurl = entry.link[k].href;
break;
}
}
var recenthumb;
try {
recenthumb = entry.media$postImageUrl.url;
} catch (error) {
s = entry.content.$t;
a = s.indexOf("<img");
b = s.indexOf("src=\"", a);
c = s.indexOf("\"", b + 5);
d = s.substr(b + 5, c - b - 5);
if ((a != -1) && (b != -1) && (c != -1) && (d != "")) {
recenthumb = d;
} else recenthumb = 'https://2.bp.blogspot.com/-C3Mo0iKKiSw/VGdK808U7rI/AAAAAAAAAmI/W7Ae_dsEVAE/s1600/no-thumb.png';
}
document.write('<div class="mas-elemen">');
document.write('<a href="' + postsurl + '"><img src="' + recenthumb + '"/></a>');
document.write('<h6><a href="' + postsurl + '" target ="_top">' + posttitle + '</a></h6>');
document.write('</div>');
}
document.write('</div>');
}
//]]>
</script>
<script style='text/javascript'>
var posts_no = 10;
var showpoststhumbs = true;
var readmorelink = true;
</script>
<script src="/feeds/posts/default/?orderby=published&alt=json-in-script&callback=showlatestpostswiththumbs"></script>
答案 0 :(得分:1)
由于此行而导致此错误
var entry = json.feed.entry[i];
因为传入函数showsonstpostswiththumbs的json在json.feed.entry [i]中没有值,所以现在条目未定义,请将正确的json放入该函数(showlatestpostswiththumbs),这就是我能给出的全部内容使用您问题中的信息