虽然我对Java并不是那么厌烦。这是一种使用javascript列表并选择了随机项目的方法。每次刷新页面时,都会随机选择一个引号并将其插入带有引号ID的段落中。
这种方法的优点是可以有效地对页面进行静态/缓存。
如果报价单很长,则可以通过http请求将其拉入(请参阅JSON)。我将让您研究如何添加按钮以获取其他报价。
此示例是一个很好的起点。如果这是草率的javascript,请随时进行编辑,但请尽量不要放松此解决方案的简洁性。
var quotes = [
"There's theory and then there's application. They don't always jibe.",
"That man's in a lot of trouble.",
"What can I say? To us it's a slime pit, but to them it's home."
];
function get_random_quote() {
var randomItem = quotes[Math.floor(Math.random()*quotes.length)];
return randomItem;
}
document.addEventListener("DOMContentLoaded", function(event) {
document.getElementById('quote').textContent = get_random_quote();
});