<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.div1{
position: fixed;
top:0px;
left:0px;
bottom:0px;
right:0px;
}
</style>
</head>
<body>
<button class="div1" type="button" style="border:1px solid red">点击切换</button>
<script>
function cut(){
var str='#'
let arr=['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f']
for(var i=0;i<6;i++){
let number=parseInt(Math.random()*16);
// console.log(number);
str+=arr[number]
// console.log(str);
}
return str;
}
var div=document.getElementsByClassName('div1')[0]
div.onclick=function(){
div.style.backgroundColor=cut();
}
</script>
</body>
</html>