【发布时间】:2015-09-27 08:30:18
【问题描述】:
我是 Jquery 和 Web 开发的新手,我正在尝试构建一个随机报价生成器。
Web 应用程序包含一个按钮,单击该按钮会显示新报价。这是一个静态站点,它全部使用 html/css/jquery 完成。
我的问题是单击按钮时会显示第一个引号,但再次单击时不会更改。我希望该按钮在每次单击时都显示一个新报价。
我相信这对于任何精通 Jquery 的人来说都是一个简单的解决方法:
$(document).ready(function() {
$(".quote-button").click(function() {
$('#quote-box p').html(quotes[i].q);
$('#quote-box a').attr('href', quotes[i].l);
$('quote-box a').html(quotes[i].a);
});
});
var quotes = [{
q: 'The Great Man … is colder, harder, less hesitating, and without respect and without the fear of “opinion”; he lacks the virtues that accompany respect and “respectability”, and altogether everything that is the “virtue of the herd”. If he cannot lead, he goes alone. … He knows he is incommunicable: he finds it tasteless to be familiar. … When not speaking to himself, he wears a mask. There is a solitude within him that is inaccessible to praise or blame. - Friedrich Nietzche, The Will to Power'
}, {
q: 'Power is given only to those who dare to lower themselves and pick it up. Only one thing matters, one thing; to be able to dare! Fyodor Dostoevsky'
}, {
p: 'The more sand has escaped from the hourglass of our life, the clearer we should see through it. Niccolo Machiavelli'
}
];
var i = Math.floor((Math.random() * quotes.length));
【问题讨论】:
标签: jquery button random eventhandler