我想让我的 javascript 从数组中打印一个随机引用。我设法做到了,但不知道如何控制它的写入位置。我想把它写在一个div中。帮助?
代码:
quotes = [];
quotes[0] = "I have a new philosophy. I'm only going to dread one day at a time.";
quotes[1] = "Reality is the leading cause of stress for those in touch with it.";
quotes[2] = "Few things are harder to put up with than the annoyance of a good example.";
quotes[3] = "The pure and simple truth is rarely pure and never simple.";
quotes[4] = "There's no business like show business, but there are several businesses like accounting.";
quotes[5] = "Man invented language to satisfy his deep need to complain.";
//calculate a random index
index = Math.floor(Math.random() * quotes.length);
//display the quotation
document.write("<p>" + quotes[index] + "</p>");