这样的事情,也许:
var container = $('<div id="container">');
$('body').append(container);
for (i=0; i<25; i++) {
// Random colour from http://stackoverflow.com/questions/1535128/apply-random-color-to-class-elements-individually
var hue = 'rgb(' + (Math.floor((256-199)*Math.random()) + 200) + ',' + (Math.floor((256-199)*Math.random()) + 200) + ',' + (Math.floor((256-199)*Math.random()) + 200) + ')';
$('<div class="child">').css('background-color', hue).appendTo(container);
}
Run Code Online (Sandbox Code Playgroud)
(假设这个CSS :)
#container {
width: 100px;
height: 100px;
border: 1px solid black;
}
.child {
width: 20px;
height: 20px;
float: left;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6311 次 |
| 最近记录: |