【发布时间】:2011-11-11 13:27:37
【问题描述】:
首先,一个 jsfiddle... http://jsfiddle.net/therocketforever/jYba3/11/
// Highlight selected linker link & set all others to default.
$('a.linker').click(function(){
$(this).addClass('selected');
$(this).parent('li').siblings().find('.selected').removeClass('selected');
// Selects a random colour from the 'colors' array by getting a random value
// between 0 and the length of the color array.
rand = Math.floor(Math.random()*colors.length);
$(this).css("background-color", colors[rand]);
现在是一个问题,
首先,这段代码几乎完全按照我想要的方式工作,用户单击一个链接,所选颜色应用于链接文本,从其他代码中删除,链接的背景设置为随机颜色从颜色数组中。很酷。
我想知道的是......我将如何做到这一点,以便从非选定链接中删除随机设置的背景颜色(即。只有具有 .selected 类的链接具有背景颜色。)
额外信用
如果相同的背景颜色从未连续使用两次,则奖励积分。 (即如果点击一设置为黄色,点击二为除黄色以外的任何其他颜色。
【问题讨论】:
标签: javascript jquery