它看起来非常好,因为它保持锁定到特定日期并且在刷新时不会改变,但我想将作者添加到数组中。 如:
引用 //作者
让作者在下一行显示,以及随机化报价单。
任何提示?
<script type="text/JavaScript">
var quote = new Array();
quote[0] = 'quote 1 Lorem ipsum dolor sit amet, consectetuer adipiscing elit.';
quote[1] = 'quote 2 Nullam commodo venenatis elit. In aliquam.';
quote[2] = 'quote 3 Sed vitae risus ac urna pharetra tristique.';
quote[3] = 'quote 4 Maecenas id mi quis nisl porta sodales.';
quote[4] = 'quote 5 Fusce lorem velit, tempor sit amet, luctus nec, suscipit at, velit';
quote[5] = 'quote 6 Ut pellentesque mauris non justo. In varius.';
quote[6] = 'quote 7 Phasellus non urna dignissim nisl mollis consectetuer.';
var qlen = quote.length;
var firstDate = new Date(2005,0,1);//start date (yyyy,m,d) - m=0=January, m=1=February
var today = new Date();//today
var dif = Math.floor((today-firstDate)/1000/60/60/24);//difference in days
while(dif>=qlen){//calculate the index of the quote of the day
dif=dif-qlen;//restart the array index if the difference is greater that the array's length
}
var todayQuote = quote[dif];//the quote of the day
onload = function(){document.getElementById('q').firstChild.data = todayQuote}
</script>
</head>
<body>
<div id='q'> </div>
</body>
</html>
答案 0 :(得分:0)
我知道这是迟到的答案。
<script type="text/JavaScript">
var quote = new Array();
quote[0] = ['quote 1 Lorem ipsum dolor sit amet, consectetuer adipiscing elit.',"some text"];
quote[1] = ['quote 2 Lorem ipsum dolor sit amet',"some text"];
var qlen = quote.length;
var firstDate = new Date(2005,0,1);//start date (yyyy,m,d) - m=0=January, m=1=February
var today = new Date();//today
var dif = Math.floor((today-firstDate)/1000/60/60/24);//difference in days
while(dif>=qlen){//calculate the index of the quote of the day
dif=dif-qlen;//restart the array index if the difference is greater that the array's length
}
var todayQuote = quote[dif];
onload = function(){document.getElementById('q').firstChild.data = todayQuote}
</script>