我正在编写一个程序,当单击一个按钮时,它会使文本从数组中随机出现(我已完成此部分)。我需要帮助的是让按钮能够反复按下并且每次都显示其他内容。
input type="button" value="Maths"
onClick = "document.getElementById('4').style.display='block';">
div id="4" style="display:none;"
script language="Javascript"
sent = new Array (6);
sent [0] = "Don't cry because it's over. Smile because it happened. -Dr.Seuss";
sent [1] = "So many books, so little time. -Frank Zappa";
sent [2] = "In three words I can sum up everything I've learned about life: it goes on. -Robert Frost";
sent [3] = "If you tell the truth, you don't have to remember anything. -Mark Twain";
sent [4] = "To live is the rarest thing in the world. Most people exist, that is all. -Oscar Wilde";
sent [5] = "To be yourself in a world that is constantly trying to make you something else is the greatest accomplishment. - Ralph Waldo Emerson";
x=Math.floor(Math.random()*6);
document.write(sent[x])
/script/div
答案 0 :(得分:0)
你应该把它放在一个循环中。这将使代码持久化。
while (condition) {
code block to be executed
}
答案 1 :(得分:0)
从数组中删除显示的元素
sent.splice(x,1);