我想加載頁面加載的隨機視頻。這是我認爲可能會發揮作用的一些JavaScript。我不熟悉JavaScript,所以可能有更簡單的方法來做到這一點...任何想法?如果您使用數組嘗試在頁面加載時顯示隨機視頻
function random_video {
var string1 = '<div class="span4"><h3 class="meet">Meet the Makers</h3><iframe width="100%" height="200" src="http://www.youtube.com/embed/Ig-DbfPoz3o" frameborder="0" allowfullscreen></iframe></div>';
var string2 = '<div class="span4"><h3 class="meet">Meet the Makers</h3><iframe width="100%" height="200" src="http://www.youtube.com/embed/estPhyfBGho" frameborder="0" allowfullscreen=""></iframe></div>';
var string3 = '<div class="span4"><h3 class="meet">Meet the Makers</h3><iframe width="100%" height="200" src="http://www.youtube.com/embed/6JL4hpnZklk" frameborder="0" allowfullscreen=""></iframe></div>';
var number = Math.floor((Math.random()*3)+1);
if (number == 1) {
document.write(string1);
} else (number == 2) {
document.write(string2);
} else (number == 3) {
document.write(string3);
}
};
的if/else條件需要更多的IFS你的(如:'否則,如果(...')。 – j08691 2012-04-09 21:17:07