1
Это выглядит очень хорошо, поскольку он фиксируется в определенный день и не изменяется при обновлении, но я хочу добавить авторов в массив. , такие как:JavaScript Котировки дня с присвоенными авторами
Quote // Автор
с авторами отображаются на следующей строке, а также рандомизации котировки заказа.
Любые советы?
<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>
Вы можете использовать json. quote [0] = {quote: 'some text', author: 'name'} ;. – Hosar