不知道为啥无法遍历chrome.topSites 的数据,开始能用,后来不知道怎么回事就不停的报错
chrome.topSites.get(function(u){
n = n||12;//传入
var h='<p class="mostVisited"><p>访问最多:</p>';
if(u.length<=0){
h+='<p class="mv-none">nonthing</p>';
}else{
for(var i=0;i<n;i++){
h+='<a class="mv-item" href="'+u[i].url+'">';
h+='<p class="mvi-icon"><img src="chrome://favicon/'+u[i].url+'"/></p>';
h+='<p class="mvi-content">';
h+='<p class="mvic-title">'+u[i].title+'</p>';
h+='<p class="mvic-url">'+u[i].url+'</p>';
h+='</p>';
}
}
h+='</p>';
$('.content').html(h);
});
console.log()可以输出信息,就是for循环时候报错,提示:
Error in response to topSites.get: TypeError: Cannot read property 'url' of undefined

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
n = n || 12,for(var i=0;i<n;i++) 你想想u.length < n的时候会咋样咧