一、效果图
二、使用步骤
1.js代码
<script type="text/javascript">var _box1=document.getElementById("box1");function bgcolor (tag) {tag.style.backgroundColor=randomnumber();}function randomnumber () {var a=Math.floor(Math.random()*256);var b=Math.floor(Math.random()*256);var c=Math.floor(Math.random()*256);return `rgb(${a},${b},${c})`;}</script>
2.html代码
<div id="box1" onclick="bgcolor(this)"></div>