<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#app{
width:200px;
height:200px;
border:2px solid black;
}
</style>
</head>
<body>
<div id="app" onclick="setBgc()"></div>
<script>
function setBgc(){
//获取app
let _app=document.getElementById("app");
//添加背景颜色
_app.style.backgroundColor=randomColor();
}
function randomColor(){
let r=Math.ceil(Math.random()*255);
let g=Math.ceil(Math.random()*255);
let b=Math.ceil(Math.random()*255);
return `rgb(${r},${g},${b})`;
}
</script>
</body>
</html>