Ich frage mich, ob jemand bei dieser Aufgabe helfen kann; Ich habe diesen tollen Code für ein Tageszitat gefunden und versuche nur einen Zeilenumbruch zwischen dem Tageszitat und dem Autor des Zitats zu machen. Ich dachte, vielleicht wäre es einfacher, ein zweidimensionales Array zu erstellen, aber leider konnte ich nicht herausfinden, wie ich den Zeilenumbruch machen sollte. Vielen Dank. Hier ist der Code so weit:Zeilenumbrüche zwischen Javascript-Array-Elementen hinzufügen
<script type="text/JavaScript">
var quote = new Array()
for (i=0; i<7; i++){
quote[i] = new Array(6)
}
quote[0][0] = 'If you want to go fast go alone, if you want to go far go together!';
quote[0][1] = 'African Proverb';
quote[1][0] = 'We either make ourselves happy or miserable. The amount of work is the same.';
quote[1][1] = 'Carlos Castaneda';
quote[2][0] = 'Everything should be made as simple as possible, but not any simpler.';
quote[2][1] = 'Albert Einstein';
quote[3][0] = 'Failure is the mother of success.';
quote[3][1] = 'Chinese Proverb';
quote[4][0] = 'The first to apologize is the bravest. The first to forgive is the strongest. The first to forget is the happiest.'
quote[4][1] = 'Unknown';
quote[5][0] = 'If an egg is broken by an outside force, life ends. If it is broken by an inside force life begins. Great things happen from the inside.';
quote[5][1] = 'Unknown';
quote[6][0] = 'Simplicity is the ultimate sophistication.'
quote[6][1] = 'Leonardo Da Vinci';
var qlen = quote.length;
var firstDate = new Date(2016,2,25);//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][0];//the quote of the day
var todayQuoteOwner = quote[dif][1];//author of the quote of the day
onload = function(){document.getElementById('q').firstChild.data = todayQuote + </n> + document.getElementById('qu').firstChild.data = todayQuoteOwner}
</script>
<div> id='q'; </div>
'document.getElementById ('q'). FirstChild.data = todayQuote + "\ r \ n" + document.getElementById ('qu'). FirstChild.data todayQuoteOwner' =? – Gogol
oder bei Ausgabe in HTML, 'document.getElementById ('q'). FirstChild.data = todayZitat +"
"+ document.getElementById ('qu'). FirstChild.data = todayQuoteOwner'? – Gogol
Es gibt eine, die nicht da sein sollte. –