我设置了一个脚本,以便可以在网站上嵌入各种 Facebook 帖子。这个想法是,它会随机加载一个帖子,然后点击按钮加载另一个。当我单击按钮时,上一个帖子消失了,但我要求的新帖子没有出现。
任何人都可以解释一下吗?
Javascript:
var comps = new Array();
comps[0] = "\"https://www.facebook.com/permalink.php?story_fbid=10151746360309352&id=9212109351\"";
comps[1] = "\"https://www.facebook.com/photo.php?fbid=10202149995929199&set=a.3217789641447.156870.1167545588&type=1\"";
var firstLine = "<div id=\"fb-root\"></div>";
var secondLine = "<div class=\"fb-post\" data-href=";
var thirdLine = " data-width=\"550\"></div>";
var randomComp = firstLine + secondLine + comps[Math.floor(Math.random()* comps.length)] + thirdLine;
window.onload=function(){
document.getElementById('compsContainer').innerHTML = randomComp;
}
function changeComp(){
document.getElementById('compsContainer').innerHTML = randomComp;
}
HTML:
<div id="compsContainer">
</div>
<input type='button' onclick='changeComp()' value='Change Comp'/>