Html
    Css
    Js
1
2
3
4
5
<div>
<ul>
</ul>
<button></button>
</div>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
* {
margin:0;
padding:0
}
div {
width:600px;
margin:200px auto;
padding:1rem;
border:1px solid red;
text-align:center
}
ul {
list-style:none;
width:100%;
overflow:hidden;
display:none
}
ul:first-of-type {
display:block
}
ul li {
width:20%;
float:left;
text-align:center;
margin:.5rem 2.5%;
padding:.5rem 0;
border-radius:4px
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
$(function() {
var bac = ["#b1181a", "#ff7375", "#a8e8ff", "#f2a8ff", "#f5b879"];
var color = ["black", "white"];
var content = ["", "", "", "", "", "", "", "", ""];
for (var i = 0; i < 8; i++) {
var cot = content[Math.floor(Math.random() * 9)];
var li = "<li>" + cot + "</li>";
$("ul").append(li);
}
$("ul li").each(function() {
$(this).css({
"background-color": bac[Math.floor(Math.random() * 5)],
"color": color[Math.floor(Math.random() * 2)]
})
});
$("button").click(function() {
$("ul").empty();
for (var i = 0; i < 8; i++) {
var cot = content[Math.floor(Math.random() * 9)];
var li = "<li>" + cot + "</li>";
$("ul").append(li);
}
$("ul li").each(function() {
$(this).css({
"background-color": bac[Math.floor(Math.random() * 5)],
"color": color[Math.floor(Math.random() * 2)]
})
});
})
})
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
↑上面代码改变,会自动显示代码结果 jQuery调用版本:1.11.3
 立即下载

随机生成名字换一换

变变变 懂得越多 不会的也就越多

2
      Time Machine0
      2018/11/4 0:38:59
      可以试着将 汉子解码  然后随机生成解码的汉字  放入content中  效果可能会更好
      回复
      yEs、先生0
      2018/11/2 15:52:56
      管顿饭过的过的

      回复