You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
509 B
JavaScript
20 lines
509 B
JavaScript
2 years ago
|
// #region 随机背景色
|
||
|
|
||
|
function GetRandomColor() {
|
||
|
var r = Math.floor(Math.random() * 255);
|
||
|
var g = Math.floor(Math.random() * 255);
|
||
|
var b = Math.floor(Math.random() * 255);
|
||
|
|
||
|
return "rgb(" + r + "," + g + "," + b + ")";
|
||
|
}
|
||
|
|
||
|
function ChangeColor(event){
|
||
|
event.currentTarget.style.backgroundColor = GetRandomColor();
|
||
|
};
|
||
|
|
||
|
//设置单击事件
|
||
|
var items = document.getElementsByClassName("item");
|
||
|
for (var i = 0; i < items.length; i++) {
|
||
|
items[i].onclick = ChangeColor;
|
||
|
}
|
||
|
// #endregion
|