我页面上有一系列相同类别的DIV。在页面加载时,我希望随机选择每个DIV的颜色。
我想为给定的DIV选择一个颜色,然后为下一个DIV选择一个颜色,以此类推。
我找到了这篇文章:Apply random color to class elements individually? 虽然我不理解jQuery,但我已经开始通过更改代码来反映我使用的类别名称:
我想为给定的DIV选择一个颜色,然后为下一个DIV选择一个颜色,以此类推。
我找到了这篇文章:Apply random color to class elements individually? 虽然我不理解jQuery,但我已经开始通过更改代码来反映我使用的类别名称:
$(document).ready(function() {
$('.main').each(function () {
var hue = 'rgb(' + (Math.floor((256-199)*Math.random()) + 200) + ',' + (Math.floor((256-199)*Math.random()) + 200) + ',' + (Math.floor((256-199)*Math.random()) + 200) + ')';
$(.jump-response).css("background-color", hue);
});
});
非常感激您提供的帮助!
--
这里有一个代码示例:http://jsfiddle.net/ollyf/LmwYP/
同时我还应该补充说明,随机背景颜色来自预设/确定的颜色列表。
.jump-response
元素并在每次迭代中设置相同元素的背景之外,似乎还有什么问题? - adeneo